hash method
Creates a combined hash code for a number of objects.
The hash code is computed for all arguments that are actually
supplied, even if they are null
, by numerically combining the
Object.hashCode of each argument.
Example:
class SomeObject {
final Object a, b, c;
SomeObject(this.a, this.b, this.c);
bool operator ==(Object other) =>
other is SomeObject && a == other.a && b == other.b && c == other.c;
int get hashCode => Object.hash(a, b, c);
}
The computed value will be consistent when the function is called with the same arguments multiple times during the execution of a single program.
The hash value generated by this function is not guaranteed to be stable over different runs of the same program, or between code run in different isolates of the same program. The exact algorithm used may differ between different platforms, or between different versions of the platform libraries, and it may depend on values that change on each program execution.
The hashAll function gives the same result as this function when called with a collection containing the actual arguments to this function in the same order.
Implementation
@override
int hash(List<E>? list) {
if (list == null) return null.hashCode;
// Jenkins's one-at-a-time hash function.
// This code is almost identical to the one in IterableEquality, except
// that it uses indexing instead of iterating to get the elements.
var hash = 0;
for (var i = 0; i < list.length; i++) {
var c = _elementEquality.hash(list[i]);
hash = (hash + c) & _hashMask;
hash = (hash + (hash << 10)) & _hashMask;
hash ^= hash >> 6;
}
hash = (hash + (hash << 3)) & _hashMask;
hash ^= hash >> 11;
hash = (hash + (hash << 15)) & _hashMask;
return hash;
}