Skip to content

Commit

Permalink
Merge pull request #13 from hashlookup/fix-version-1
Browse files Browse the repository at this point in the history
Fix version 1
  • Loading branch information
qjerome authored Jul 29, 2024
2 parents 9890231 + 75a7bed commit 76aa759
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
6 changes: 5 additions & 1 deletion poppy/src/bin/poppy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,15 @@ fn parallel_insert(
jobs: usize,
verbose: bool,
) -> Result<BloomFilter, anyhow::Error> {
if files.is_empty() {
return Ok(bf);
}

let jobs = optimal_jobs(jobs);

let batches = files.chunks(max(files.len() / jobs, 1));
let mut bfs = vec![];
for _ in 0..(batches.len() - 1) {
for _ in 0..(batches.len().saturating_sub(1)) {
bfs.push(bf.clone())
}
// we move bf to prevent doing an additional copy
Expand Down
28 changes: 23 additions & 5 deletions poppy/src/bloom/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ impl BloomFilter {
/// checks if an entry is contained in the bloom filter
#[inline(always)]
pub fn contains_bytes<S: AsRef<[u8]>>(&self, value: S) -> bool {
let mut ret = false;
if self.bitset.is_empty() {
return false;
}
for index in self.fingerprint.fingerprint(value) {
ret |= self.get_nth_bit(index);
// if one bit is missing we early return
if !ret {
if !self.get_nth_bit(index) {
return false;
}
}
ret
true
}

/// counts all the set bits in the bloom filter
Expand Down Expand Up @@ -453,6 +453,22 @@ mod test {
};
}

#[test]
fn test_fingerprint() {
let mut f = Fingerprint::new(7, 958505).fingerprint("bar");

// These are the expected values from TestFingerprinting in bloom_test.go
// expected := [7]uint64{20311, 36825, 412501, 835777, 658914, 853361, 307361}
assert_eq!(f.next(), Some(20311));
assert_eq!(f.next(), Some(36825));
assert_eq!(f.next(), Some(412501));
assert_eq!(f.next(), Some(835777));
assert_eq!(f.next(), Some(658914));
assert_eq!(f.next(), Some(853361));
assert_eq!(f.next(), Some(307361));
assert_eq!(f.next(), None);
}

#[test]
fn test_bloom() {
let mut b = bloom!(100000, 0.001);
Expand Down Expand Up @@ -517,6 +533,8 @@ mod test {
assert!(b.contains_bytes("hello"));
assert!(b.contains_bytes("world"));
assert!(!b.contains_bytes("hello world"));
assert!(!b.contains_bytes("this"));
assert!(!b.contains_bytes("that"));
}

#[test]
Expand Down

0 comments on commit 76aa759

Please sign in to comment.