From 5c7b66e07a3811b3fa0b8e7bbfe4cf25a6361d3a Mon Sep 17 00:00:00 2001 From: Lolo Iccl Date: Sat, 5 May 2018 08:06:29 +0900 Subject: Modify previous commit and add tests --- lib/pure/collections/sets.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/pure') diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index 900f281e9..94bdbb860 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -18,7 +18,7 @@ ## that ``=`` performs a copy of the set. import - hashes, math + hashes, math, algorithm {.pragma: myShallow.} when not defined(nimhygiene): @@ -123,8 +123,11 @@ iterator items*[A](s: HashSet[A]): A = proc hash*[A](s: HashSet[A]): Hash = ## hashing of HashSet assert s.isValid, "The set needs to be initialized." + var hcs: seq[Hash] for h in 0..high(s.data): - result = result !& s.data[h].hcode + hcs.add(s.data[h].hcode) + for hc in sorted(hcs, cmp[int]): + result = result !& hc result = !$result const -- cgit 1.4.1-2-gfad0