Using DefaultHasher instead of SipHasher

This commit is contained in:
Tomasz Drwięga 2016-10-21 11:16:55 +02:00
parent b2da168ff2
commit 5aadda95c3

View File

@ -17,7 +17,8 @@
use std::cmp; use std::cmp;
use std::mem; use std::mem;
use std::f64; use std::f64;
use std::hash::{Hash, Hasher, SipHasher}; use std::hash::{Hash, Hasher, BuildHasher};
use std::collections::hash_map::RandomState;
use std::collections::HashSet; use std::collections::HashSet;
/// BitVec structure with journalling /// BitVec structure with journalling
@ -73,7 +74,7 @@ pub struct Bloom {
bitmap: BitVecJournal, bitmap: BitVecJournal,
bitmap_bits: u64, bitmap_bits: u64,
k_num: u32, k_num: u32,
sips: [SipHasher; 2], sips: [RandomState; 2],
} }
impl Bloom { impl Bloom {
@ -85,7 +86,7 @@ impl Bloom {
let bitmap_bits = (bitmap_size as u64) * 8u64; let bitmap_bits = (bitmap_size as u64) * 8u64;
let k_num = Bloom::optimal_k_num(bitmap_bits, items_count); let k_num = Bloom::optimal_k_num(bitmap_bits, items_count);
let bitmap = BitVecJournal::new(bitmap_bits as usize); let bitmap = BitVecJournal::new(bitmap_bits as usize);
let sips = [Bloom::sip_new(), Bloom::sip_new()]; let sips = [RandomState::default(), RandomState::default()];
Bloom { Bloom {
bitmap: bitmap, bitmap: bitmap,
bitmap_bits: bitmap_bits, bitmap_bits: bitmap_bits,
@ -99,7 +100,7 @@ impl Bloom {
let bitmap_size = parts.len() * 8; let bitmap_size = parts.len() * 8;
let bitmap_bits = (bitmap_size as u64) * 8u64; let bitmap_bits = (bitmap_size as u64) * 8u64;
let bitmap = BitVecJournal::from_parts(parts); let bitmap = BitVecJournal::from_parts(parts);
let sips = [Bloom::sip_new(), Bloom::sip_new()]; let sips = [RandomState::default(), RandomState::default()];
Bloom { Bloom {
bitmap: bitmap, bitmap: bitmap,
bitmap_bits: bitmap_bits, bitmap_bits: bitmap_bits,
@ -174,8 +175,8 @@ impl Bloom {
where T: Hash where T: Hash
{ {
if k_i < 2 { if k_i < 2 {
let sip = &mut self.sips[k_i as usize].clone(); let mut sip = self.sips[k_i as usize].build_hasher();
item.hash(sip); item.hash(&mut sip);
let hash = sip.finish(); let hash = sip.finish();
hashes[k_i as usize] = hash; hashes[k_i as usize] = hash;
hash hash
@ -184,10 +185,6 @@ impl Bloom {
} }
} }
fn sip_new() -> SipHasher {
SipHasher::new()
}
/// Drains the bloom journal returning the updated bloom part /// Drains the bloom journal returning the updated bloom part
pub fn drain_journal(&mut self) -> BloomJournal { pub fn drain_journal(&mut self) -> BloomJournal {
BloomJournal { BloomJournal {