diff options
author | Lolo Iccl <oxisccl@gmail.com> | 2018-05-05 05:33:54 +0900 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-05-09 17:41:41 +0200 |
commit | 80f17f94053dbf79e851ac2c90dd6e108c178a61 (patch) | |
tree | a82868aa25a77cfde5d83931bc14542ea0d421f1 /lib | |
parent | 9bde9a1404a979e9a19601a1355f893565d4f218 (diff) | |
download | Nim-80f17f94053dbf79e851ac2c90dd6e108c178a61.tar.gz |
Add proc hash for HashSet and for OrderedSet
close #7772
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/collections/sets.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index 32b6387ad..0019f8e3a 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -120,6 +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 = + ## hashing of HashSet + for item in x: result = result !& hash(item) + result = !$result + const growthFactor = 2 @@ -690,6 +695,11 @@ iterator items*[A](s: OrderedSet[A]): A = forAllOrderedPairs: yield s.data[h].key +proc hash*[A](x: OrderedSet[A]): Hash = + ## hashing of OrderedSet + for item in x: result = result !& hash(item) + result = !$result + iterator pairs*[A](s: OrderedSet[A]): tuple[a: int, b: A] = assert s.isValid, "The set needs to be initialized" forAllOrderedPairs: |