equals method
Compare two elements for being equal.
This should be a proper equality relation.
Implementation
@override
bool equals(T? elements1, T? elements2) {
if (identical(elements1, elements2)) {
return true;
}
if (elements1 == null || elements2 == null) {
return false;
}
final HashMap<E, int> counts = HashMap<E, int>(
equals: _elementEquality.equals,
hashCode: _elementEquality.hash,
isValidKey: _elementEquality.isValidKey,
);
int length = 0;
for (final E e in elements1) {
final int count = counts[e] ?? 0;
counts[e] = count + 1;
length++;
}
for (final E e in elements2) {
final int? count = counts[e];
if (count == null || count == 0) {
return false;
}
counts[e] = count - 1;
length--;
}
return length == 0;
}