pub mod standard;
pub use standard::StandardFilterSerdeSupport;
pub mod counting;
pub use counting::CountingFilterSerdeSupport;
pub mod sharded;
pub use sharded::ShardedFilterSerdeSupport;
pub mod striped;
pub use striped::StripedFilterSerdeSupport;
pub const SERIALIZATION_VERSION: u16 = 1;
pub trait SerializableFilter {
fn filter_type() -> &'static str;
fn format_version() -> u16 {
SERIALIZATION_VERSION
}
}
#[derive(Debug, Clone, Copy)]
pub struct FilterParameters {
pub size: usize,
pub num_hashes: usize,
pub hash_strategy: u8,
pub extra: [u64; 4],
}
impl FilterParameters {
pub const fn new(size: usize, num_hashes: usize, hash_strategy: u8) -> Self {
Self {
size,
num_hashes,
hash_strategy,
extra: [0; 4],
}
}
pub fn with_extra(mut self, index: usize, value: u64) -> Self {
if index < 4 {
self.extra[index] = value;
}
self
}
}
pub mod prelude {
pub use super::{
CountingFilterSerdeSupport, SerializableFilter, ShardedFilterSerdeSupport,
StandardFilterSerdeSupport, StripedFilterSerdeSupport,
};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_filter_parameters() {
let params = FilterParameters::new(1000, 7, 1)
.with_extra(0, 42)
.with_extra(1, 100);
assert_eq!(params.size, 1000);
assert_eq!(params.num_hashes, 7);
assert_eq!(params.hash_strategy, 1);
assert_eq!(params.extra[0], 42);
assert_eq!(params.extra[1], 100);
assert_eq!(params.extra[2], 0);
}
#[test]
fn test_serialization_constants() {
const _: () = assert!(SERIALIZATION_VERSION > 0);
}
}