Skip to content

Commit

Permalink
change when false into commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Mar 15, 2020
1 parent 7aefb5d commit 79d73c0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/pure/collections/sets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -578,18 +578,16 @@ proc hash*[A](s: HashSet[A]): Hash =
# This handles tombstones (iterating over all `s.data` would be wrong).
# Iterating over items(s) requires a commutative hash combiner like `xor`
# to avoid depending on order (which could differ for 2 HashSet's with different
# `data.len` but same elements, after insertions and deletions). But `xor`
# has bad mixing properties (eg, would give 0 if HashSet contains
# `data.len` but same elements, after insertions and deletions), eg:
# for h in s:
# result = result xor hash(h)
# But `xor` has bad mixing properties (eg, would give 0 if HashSet contains
# a, b such that hash(a) == hash(b) and a != b). `sort` should have low
# overhead compared to the surrounding code.
when true:
var s2: seq[Hash]
for h in s: s2.add hash(h)
s2.sort
for h in s2: result = result !& hash(h)
else:
for h in s:
result = result xor hash(h)
var s2: seq[Hash]
for h in s: s2.add hash(h)
s2.sort
for h in s2: result = result !& hash(h)
result = !$result

proc `$`*[A](s: HashSet[A]): string =
Expand Down

0 comments on commit 79d73c0

Please sign in to comment.