From 3ad2e7df1cfb0b454a96dbbc10b2684d1f53dc9b Mon Sep 17 00:00:00 2001 From: Bung Date: Wed, 21 Jun 2023 18:19:40 +0800 Subject: fix #20023 hash for generic tables (#20346) * fix #20023 hash for generic tables * use default computation * Update lib/pure/collections/tables.nim Co-authored-by: Dan Rose * Update lib/pure/collections/tables.nim Co-authored-by: Dan Rose * Update lib/pure/collections/tables.nim * Update lib/pure/collections/tables.nim * Update t20023.nim --------- Co-authored-by: Dan Rose Co-authored-by: Andreas Rumpf --- lib/pure/collections/tables.nim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/pure/collections/tables.nim') diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 9ecc6b8e6..53490c911 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -2901,3 +2901,18 @@ iterator mvalues*[A](t: CountTableRef[A]): var int = if t.data[h].val != 0: yield t.data[h].val assert(len(t) == L, "the length of the table changed while iterating over it") + +proc hash*[K,V](s: Table[K,V]): Hash = + for p in pairs(s): + result = result xor hash(p) + result = !$result + +proc hash*[K,V](s: OrderedTable[K,V]): Hash = + for p in pairs(s): + result = result !& hash(p) + result = !$result + +proc hash*[V](s: CountTable[V]): Hash = + for p in pairs(s): + result = result xor hash(p) + result = !$result \ No newline at end of file -- cgit 1.4.1-2-gfad0