From d8a094cc43f7e16b715b8a2fed4c24a4040197ea Mon Sep 17 00:00:00 2001 From: Heyuan Zeng Date: Thu, 15 Aug 2024 00:13:20 +0200 Subject: [PATCH 1/2] Fix hashing overflow issues --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3b0cfbd..47499bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; fn hash_shuffle_bits(h: usize) -> usize { - ((h ^ 89869747) ^ (h << 16)) * 3644798167 + ((h ^ 89869747) ^ (h << 16)).wrapping_mul(3644798167) } #[derive(Debug)] @@ -217,11 +217,11 @@ impl HashTrieMapPy { })?; // factor in the number of entries in the collection - hash_val ^= (self.inner.size() + 1) * 1927868237; + hash_val ^= self.inner.size().wrapping_add(1).wrapping_mul(1927868237); // dispense patterns in the hash value hash_val ^= (hash_val >> 11) ^ (hash_val >> 25); - hash_val = hash_val * 69069 + 907133923; + hash_val = hash_val.wrapping_mul(69069).wrapping_add(907133923); Ok(hash_val as isize) } @@ -833,11 +833,11 @@ impl HashTrieSetPy { .fold(0, |acc: usize, x: usize| acc ^ hash_shuffle_bits(x)); // factor in the number of entries in the collection - hash_val ^= (self.inner.size() + 1) * 1927868237; + hash_val ^= self.inner.size().wrapping_add(1).wrapping_mul(1927868237); // dispense patterns in the hash value hash_val ^= (hash_val >> 11) ^ (hash_val >> 25); - hash_val = hash_val * 69069 + 907133923; + hash_val = hash_val.wrapping_mul(69069).wrapping_add(907133923); Ok(hash_val as isize) } From edc02d68279f3a7e6a569204518e43886639b596 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Thu, 31 Oct 2024 10:03:50 -0400 Subject: [PATCH 2/2] Set --profile=dev in tests to catch issues like #86. --- noxfile.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 11e1f98..92655fa 100644 --- a/noxfile.py +++ b/noxfile.py @@ -38,7 +38,18 @@ def tests(session): """ Run the test suite with a corresponding Python version. """ - session.install("-r", REQUIREMENTS["tests"]) + # Really we want --profile=test here (for + # https://github.com/crate-py/rpds/pull/87#issuecomment-2291409297) + # but it produces strange symbol errors saying: + # dynamic module does not define module export function (PyInit_rpds) + # so OK, dev it is. + session.install( + "--config-settings", + "build-args=--profile=dev", + "--no-cache", + "-r", + REQUIREMENTS["tests"], + ) if session.posargs and session.posargs[0] == "coverage": if len(session.posargs) > 1 and session.posargs[1] == "github":