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).

Also update the corresponding basic test.
  • Loading branch information
d-torrance committed Sep 11, 2024
1 parent 954e44c commit b9bd9c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 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 if b.v then hash_t(444777) else hash_t(777334)
is Nothing do hash_t(333889)
is x:List do x.hash
is f:functionCode do f.hash
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/m2/basictests/hashcodes.m2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ assert( (hash (1 => 2)) === 1729140528276943882 )
assert( hash Nothing == 1000069 )
assert( (hash Boolean) === 1000035 )
assert( (hash true) === 444777 )
assert( (hash false) === 777333 )
assert( (hash false) === 777334 )

-- 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 b9bd9c7

Please sign in to comment.