From 2123cf6b74d3cec7e03ee71fefd4c709db45eba7 Mon Sep 17 00:00:00 2001 From: Doug Torrance Date: Wed, 11 Sep 2024 05:55:24 -0400 Subject: [PATCH] Ensure that "true" and "false" won't go in same bucket in hash table Previously, "hash true" and "hash false" were both congruent to 1 (mod 4). Also update the corresponding basic test. --- M2/Macaulay2/d/basic.d | 2 +- M2/Macaulay2/m2/basictests/hashcodes.m2 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/M2/Macaulay2/d/basic.d b/M2/Macaulay2/d/basic.d index 21b6ad1ca26..b0ad7dd877d 100644 --- a/M2/Macaulay2/d/basic.d +++ b/M2/Macaulay2/d/basic.d @@ -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(1) else hash_t(0) is Nothing do hash_t(333889) is x:List do x.hash is f:functionCode do f.hash diff --git a/M2/Macaulay2/m2/basictests/hashcodes.m2 b/M2/Macaulay2/m2/basictests/hashcodes.m2 index 92b4f0ccbc2..a859028b952 100644 --- a/M2/Macaulay2/m2/basictests/hashcodes.m2 +++ b/M2/Macaulay2/m2/basictests/hashcodes.m2 @@ -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 *- )