Skip to content

Commit

Permalink
uses ahash::RandomState::hash_one in deduper::Deduper
Browse files Browse the repository at this point in the history
ahash::RandomState has specializations for hashing single value, which
can be faster for primitive types:
https://github.com/tkaitchuck/aHash/blob/7d5c661a7/src/random_state.rs#L317
https://github.com/tkaitchuck/aHash/blob/7d5c661a7/src/specialize.rs#L17-L19
  • Loading branch information
behzadnouri committed Dec 19, 2024
1 parent f06f5db commit 8f5890e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions perf/src/deduper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
ahash::RandomState,
rand::Rng,
std::{
hash::{BuildHasher, Hash, Hasher},
hash::Hash,
iter::repeat_with,
marker::PhantomData,
sync::atomic::{AtomicU64, Ordering},
Expand Down Expand Up @@ -67,10 +67,8 @@ impl<const K: usize, T: ?Sized + Hash> Deduper<K, T> {
#[allow(clippy::arithmetic_side_effects)]
pub fn dedup(&self, data: &T) -> bool {
let mut out = true;
let hashers = self.state.iter().map(RandomState::build_hasher);
for mut hasher in hashers {
data.hash(&mut hasher);
let hash: u64 = hasher.finish() % self.num_bits;
for random_state in &self.state {
let hash: u64 = random_state.hash_one(data) % self.num_bits;
let index = (hash >> 6) as usize;
let mask: u64 = 1u64 << (hash & 63);
let old = self.bits[index].fetch_or(mask, Ordering::Relaxed);
Expand Down

0 comments on commit 8f5890e

Please sign in to comment.