Skip to content

Commit

Permalink
Implement helper for deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jul 24, 2023
1 parent 43d8976 commit 2a15c2a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions deterministic-bloom/src/runtime_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ impl BloomFilter {
}
}

/// Construct the bloom filter from existing components.
///
/// This is useful when e.g. deserializing a bloom filter.
///
/// # Example
///
/// ```
/// use deterministic_bloom::runtime_size::BloomFilter;
///
/// let mut filter = BloomFilter::new_from_fpr_po2(100_000, 0.01);
///
/// filter.insert(b"Hello, World!");
///
/// // Serialize
/// let k_hashes = filter.hash_count();
/// let bytes = Box::from(filter.as_bytes());
///
/// // Deserialize
/// let filter2 = BloomFilter::new_with(k_hashes, bytes);
/// assert_eq!(filter, filter2);
/// ```
pub fn new_with(k_hashes: usize, bytes: Box<[u8]>) -> Self {
Self { k_hashes, bytes }
}

/// Compute the bloom parameters for this bloom filter.
/// This contains information about its size and hash function evaluations per
/// item (`k_hashes`).
Expand Down

2 comments on commit 2a15c2a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 2a15c2a Previous: ae5bda4 Ratio
add 1390 ns/iter (± 1) 535 ns/iter (± 1) 2.60

This comment was automatically generated by workflow using github-action-benchmark.

CC: @expede

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 2a15c2a Previous: ae5bda4 Ratio
add 1540 ns/iter (± 64) 535 ns/iter (± 1) 2.88

This comment was automatically generated by workflow using github-action-benchmark.

CC: @expede

Please sign in to comment.