Skip to content

Commit

Permalink
fix a bug in hashmap implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Dec 26, 2023
1 parent 84aa831 commit 1cb8ba1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/algorithm/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ pub const EMPTY_NAN: f64 =
pub const TOMBSTONE_NAN: f64 =
unsafe { std::mem::transmute(0x7ff8_0000_0000_0000u64 | 0x0000_0000_0000_0002) };

fn hash_start<T: Hash>(value: &T, capacity: usize) -> usize {
fn hash_start<T: ArrayValue>(arr: &Array<T>, capacity: usize) -> usize {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
arr.hash(&mut hasher);
hasher.finish() as usize % capacity
}

Expand Down Expand Up @@ -319,7 +319,13 @@ impl<'a> Pair<'a> {
self.keys.row_count()
}
fn hash_start(&self, key: &Value) -> usize {
hash_start(key, self.capacity())
key.generic_ref_shallow(
|arr| hash_start(arr, self.capacity()),
|arr| hash_start(arr, self.capacity()),
|arr| hash_start(arr, self.capacity()),
|arr| hash_start(arr, self.capacity()),
|arr| hash_start(arr, self.capacity()),
)
}
fn get(&self, key: &Value) -> Option<Value> {
if self.keys.shape() == [0] {
Expand Down
2 changes: 2 additions & 0 deletions tests/units.ua
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,5 @@ Maps ← ∩(remove 1) Maps
∩(⍤. has 3) Maps
∩(⍤. has "hi") Maps
∩(⍤. has [1 2 3]) Maps

⍤⊃⋅∘≍ [2 3 4 1] ≡(get)[2 3 4 5]¤ ∧(insert) [5 2 3 4] [1 2 3 4] {}

0 comments on commit 1cb8ba1

Please sign in to comment.