From: Jean Privat Date: Sat, 14 Mar 2015 14:19:02 +0000 (+0700) Subject: lib/standard: forgot to provide `Map::hash` when `Map::==` was implemented X-Git-Tag: v0.7.3~25^2~3 X-Git-Url: http://nitlanguage.org lib/standard: forgot to provide `Map::hash` when `Map::==` was implemented Signed-off-by: Jean Privat --- diff --git a/lib/standard/collection/abstract_collection.nit b/lib/standard/collection/abstract_collection.nit index d38e001..1515ffd 100644 --- a/lib/standard/collection/abstract_collection.nit +++ b/lib/standard/collection/abstract_collection.nit @@ -497,6 +497,25 @@ interface MapRead[K, V] end return true end + + # A hashcode based on the hashcode of the keys and the values. + # + # ~~~ + # var a = new HashMap[String, Int] + # var b = new ArrayMap[Object, Numeric] + # a["one"] = 1 + # b["one"] = 1 + # assert a.hash == b.hash + # ~~~ + redef fun hash + do + var res = length + for k, v in self do + if k != null then res += k.hash * 7 + if v != null then res += v.hash * 11 + end + return res + end end # Maps are associative collections: `key` -> `item`.