equals method

  1. @override
bool equals(
  1. Map<K, V>? map1,
  2. Map<K, V>? map2
)
override

Compare two elements for being equal.

This should be a proper equality relation.

Implementation

@override
bool equals(Map<K, V>? map1, Map<K, V>? map2) {
  if (identical(map1, map2)) {
    return true;
  }
  if (map1 == null || map2 == null) {
    return false;
  }
  final int length = map1.length;
  if (length != map2.length) {
    return false;
  }
  final Map<_MapEntry, int> equalElementCounts = HashMap<_MapEntry, int>();
  for (final K key in map1.keys) {
    final _MapEntry entry = _MapEntry(this, key, map1[key]);
    final int count = equalElementCounts[entry] ?? 0;
    equalElementCounts[entry] = count + 1;
  }
  for (final K key in map2.keys) {
    final _MapEntry entry = _MapEntry(this, key, map2[key]);
    final int? count = equalElementCounts[entry];
    if (count == null || count == 0) {
      return false;
    }
    equalElementCounts[entry] = count - 1;
  }
  return true;
}