hashAllUnordered static method
This method hashes an iterable in such a way that two different iterables that have the same values, will have the same hash (regardless of order).
List<String> list1 = {"item1", "item2", "item3"};
List<String> list2 = {"item1", "item2", "item3"};
List<String> list3 = {"item6", "item7", "item8"};
hashAll(list1) == hashAll(list2) // true
hashAll(list1) == hashAll(list3) // false
Unlike hashAll, this method does not care about the order of the values.
List<String> list1 = {"item1", "item2", "item3"};
List<String> list2 = {"item2", "item3", "item1"};
hashAll(list1) == hashAll(list2) // true
Implementation
static int hashAllUnordered(Iterable iterable) {
if (iterable is Map) return hashAllUnorderedMap(iterable as Map);
List<int> hashes = [];
for (var element in iterable) {
if (element is Map) {
hashes.add(hashAllUnorderedMap(element));
} else if (element is List || element is Set || element is Iterable) {
hashes.add(hashAllUnordered(element));
} else {
hashes.add(element.hashCode);
}
}
return Object.hashAllUnordered(hashes);
}