Skip to content

Commit

Permalink
hash_one is already implemented for BuildHasher (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Soveu authored Aug 28, 2024
1 parent eabb28c commit f066f0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
10 changes: 2 additions & 8 deletions fuzz/fuzz_targets/fuzz_tree_map_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ libfuzzer_sys::fuzz_target!(|actions: Vec<Action>| {
let hash_builder = RandomState::new();
let tree_copy = tree.clone();

let original_hash = hash_one(&hash_builder, &tree);
let copy_hash = hash_one(&hash_builder, &tree_copy);
let original_hash = hash_builder.hash_one(&tree);
let copy_hash = hash_builder.hash_one(&tree_copy);

assert_eq!(original_hash, copy_hash, "{:?} != {:?}", tree, tree_copy);
},
Expand Down Expand Up @@ -187,9 +187,3 @@ libfuzzer_sys::fuzz_target!(|actions: Vec<Action>| {
}
}
});

fn hash_one(hasher_builder: &impl BuildHasher, value: impl Hash) -> u64 {
let mut hasher = hasher_builder.build_hasher();
value.hash(&mut hasher);
hasher.finish()
}
8 changes: 2 additions & 6 deletions src/collections/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1847,10 +1847,6 @@ mod tests {
assert_eq!(map_d.cmp(&map_d), Ordering::Equal);
}

fn hash_one(hasher_builder: &impl BuildHasher, value: impl Hash) -> u64 {
hasher_builder.hash_one(&value)
}

#[test]
fn tree_hash_equals() {
let mut tree_a = TreeMap::<[u8; 0], i32>::new();
Expand All @@ -1862,8 +1858,8 @@ mod tests {

let hasher_builder = RandomState::new();

let hash_a = hash_one(&hasher_builder, &tree_a);
let hash_b = hash_one(&hasher_builder, &tree_b);
let hash_a = hasher_builder.hash_one(&tree_a);
let hash_b = hasher_builder.hash_one(&tree_b);

assert_eq!(hash_a, hash_b);
}
Expand Down

0 comments on commit f066f0f

Please sign in to comment.