equals method

bool equals (Map<K, V> map1, Map<K, V> map2)
override

Compare two elements for being equal.

This should be a proper equality relation.

Implementation

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