equals method

bool equals (Set<E> elements1, Set<E> elements2)
inherited

Compare two elements for being equal.

This should be a proper equality relation.

Implementation

bool equals(T elements1, T elements2) {
  if (identical(elements1, elements2)) return true;
  if (elements1 == null || elements2 == null) return false;
  HashMap<E, int> counts = new HashMap(
      equals: _elementEquality.equals,
      hashCode: _elementEquality.hash,
      isValidKey: _elementEquality.isValidKey);
  int length = 0;
  for (var e in elements1) {
    int count = counts[e];
    if (count == null) count = 0;
    counts[e] = count + 1;
    length++;
  }
  for (var e in elements2) {
    int count = counts[e];
    if (count == null || count == 0) return false;
    counts[e] = count - 1;
    length--;
  }
  return length == 0;
}