Skip to content

Commit

Permalink
Ensure that "true" and "false" won't go in same bucket in hash table
Browse files Browse the repository at this point in the history
Previously, "hash true" and "hash false" were both congruent to 1 (mod
4).  We just set them to 1 and 0, resp.

Also update the corresponding basic test.
  • Loading branch information
d-torrance committed Sep 12, 2024
1 parent 9d1e0c2 commit 0fdbdfb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion M2/Macaulay2/d/basic.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export hash(e:Expr):hash_t := (
is s:SymbolBody do s.symbol.hash
is x:Database do x.hash
is x:ZZcell do hash(x.v)
is b:Boolean do if b.v then hash_t(444777) else hash_t(777333)
is b:Boolean do Ccode(hash_t, b.v)
is Nothing do hash_t(333889)
is x:List do x.hash
is f:functionCode do f.hash
Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/m2/basictests/hashcodes.m2
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ assert( (hash Nothing) === 1000069 )
assert( (hash (1 => 2)) === 1729140528276943882 )
assert( hash Nothing == 1000069 )
assert( (hash Boolean) === 1000035 )
assert( (hash true) === 444777 )
assert( (hash false) === 777333 )
assert( (hash true) === 1 )
assert( (hash false) === 0 )

-- these might change if our floating point implementation changes, but let's check anyway:
assert( hash 1.23p200 === 18446744072207201388 -* 64-bit *- or hash 1.23p200 == 18446744073069319069 -* 32-bit *- )
Expand Down

0 comments on commit 0fdbdfb

Please sign in to comment.