hash method

  1. @override
int hash(
  1. Iterable<E>? elements

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.


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.


int hash(T? elements) {
  if (elements == null) return null.hashCode;
  var hash = 0;
  for (E element in elements) {
    var c = _elementEquality.hash(element);
    hash = (hash + c) & _hashMask;
  hash = (hash + (hash << 3)) & _hashMask;
  hash ^= (hash >> 11);
  hash = (hash + (hash << 15)) & _hashMask;
  return hash;