From d980a335efa112d3afcf04f1222e655bde5fe6b5 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sat, 14 Mar 2015 21:19:02 +0700 Subject: [PATCH] lib/standard: forgot to provide `Map::hash` when `Map::==` was implemented Signed-off-by: Jean Privat --- lib/standard/collection/abstract_collection.nit | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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`. -- 1.7.9.5