diff --git a/agb/src/hash_map.rs b/agb/src/hash_map.rs index 4703409b..205c24ea 100644 --- a/agb/src/hash_map.rs +++ b/agb/src/hash_map.rs @@ -10,7 +10,7 @@ type HashType = u32; struct Node { hash: HashType, - distance_to_initial_bucket: u32, + distance_to_initial_bucket: i32, key: K, value: V, } @@ -48,8 +48,8 @@ impl NodeStorage { value: V, hash: HashType, number_of_elements: usize, - max_distance_to_initial_bucket: u32, - ) -> u32 { + max_distance_to_initial_bucket: i32, + ) -> i32 { debug_assert!( self.len() * 85 / 100 > number_of_elements, "Do not have space to insert into len {} with {number_of_elements}", @@ -68,7 +68,7 @@ impl NodeStorage { loop { let location = fast_mod( self.len(), - new_node.hash + new_node.distance_to_initial_bucket, + new_node.hash + new_node.distance_to_initial_bucket as HashType, ); let current_node = self.0[location].as_mut(); @@ -123,7 +123,7 @@ impl NodeStorage { pub struct HashMap { number_of_elements: usize, - max_distance_to_initial_bucket: u32, + max_distance_to_initial_bucket: i32, nodes: NodeStorage, hasher: BuildHasherDefault, @@ -196,7 +196,10 @@ where { fn get_location(&self, key: &K, hash: HashType) -> Option { for distance_to_initial_bucket in 0..=self.max_distance_to_initial_bucket { - let location = fast_mod(self.nodes.len(), hash + distance_to_initial_bucket); + let location = fast_mod( + self.nodes.len(), + hash + distance_to_initial_bucket as HashType, + ); let node = &self.nodes.0[location]; if let Some(node) = node {