From ee8313da3ff19d9340285c7177db84e1c62fc108 Mon Sep 17 00:00:00 2001 From: Lolo Iccl Date: Sat, 5 May 2018 06:20:44 +0900 Subject: [PATCH] Modify previous commit Modify previous commit to use data[h].hcode in proc hash for HashSet and for OrderedSet. --- lib/pure/collections/sets.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index 0019f8e3a5..900f281e96 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -120,9 +120,11 @@ iterator items*[A](s: HashSet[A]): A = for h in 0..high(s.data): if isFilled(s.data[h].hcode): yield s.data[h].key -proc hash*[A](x: HashSet[A]): Hash = +proc hash*[A](s: HashSet[A]): Hash = ## hashing of HashSet - for item in x: result = result !& hash(item) + assert s.isValid, "The set needs to be initialized." + for h in 0..high(s.data): + result = result !& s.data[h].hcode result = !$result const @@ -695,9 +697,11 @@ iterator items*[A](s: OrderedSet[A]): A = forAllOrderedPairs: yield s.data[h].key -proc hash*[A](x: OrderedSet[A]): Hash = +proc hash*[A](s: OrderedSet[A]): Hash = ## hashing of OrderedSet - for item in x: result = result !& hash(item) + assert s.isValid, "The set needs to be initialized." + forAllOrderedPairs: + result = result !& s.data[h].hcode result = !$result iterator pairs*[A](s: OrderedSet[A]): tuple[a: int, b: A] =