Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
remove the redundant hasher in Bloom
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawstein committed Aug 28, 2017
1 parent d90ec3d commit a13186c
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions util/bloom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ use std::hash::{Hash, Hasher};
use std::collections::HashSet;
use siphasher::sip::SipHasher;

// TODO [ToDr] Both hashers are exactly the same - no point to keep two.
const NUMBER_OF_HASHERS: usize = 2;

/// BitVec structure with journalling
/// Every time any of the blocks is getting set it's index is tracked
/// and can be then drained by `drain` method
Expand Down Expand Up @@ -80,8 +77,7 @@ pub struct Bloom {
bitmap: BitVecJournal,
bitmap_bits: u64,
k_num: u32,
// TODO [ToDr] Both hashers are exactly the same - no point to keep two.
sips: [SipHasher; NUMBER_OF_HASHERS],
sip: SipHasher,
}

impl Bloom {
Expand All @@ -93,12 +89,12 @@ impl Bloom {
let bitmap_bits = (bitmap_size as u64) * 8u64;
let k_num = Bloom::optimal_k_num(bitmap_bits, items_count);
let bitmap = BitVecJournal::new(bitmap_bits as usize);
let sips = [SipHasher::new(), SipHasher::new()];
let sip = SipHasher::new();
Bloom {
bitmap: bitmap,
bitmap_bits: bitmap_bits,
k_num: k_num,
sips: sips,
sip: sip,
}
}

Expand All @@ -107,12 +103,12 @@ impl Bloom {
let bitmap_size = parts.len() * 8;
let bitmap_bits = (bitmap_size as u64) * 8u64;
let bitmap = BitVecJournal::from_parts(parts);
let sips = [SipHasher::new(), SipHasher::new()];
let sip = SipHasher::new();
Bloom {
bitmap: bitmap,
bitmap_bits: bitmap_bits,
k_num: k_num,
sips: sips,
sip: sip,
}
}

Expand Down Expand Up @@ -178,11 +174,11 @@ impl Bloom {
cmp::max(k_num, 1)
}

fn bloom_hash<T>(&self, hashes: &mut [u64; NUMBER_OF_HASHERS], item: &T, k_i: u32) -> u64
fn bloom_hash<T>(&self, hashes: &mut [u64; 2], item: &T, k_i: u32) -> u64
where T: Hash
{
if k_i < NUMBER_OF_HASHERS as u32 {
let mut sip = self.sips[k_i as usize].clone();
if k_i < 2 {
let mut sip = self.sip.clone();
item.hash(&mut sip);
let hash = sip.finish();
hashes[k_i as usize] = hash;
Expand Down

0 comments on commit a13186c

Please sign in to comment.