pub use crate::table::filter::BloomConstructionPolicy;
#[derive(Copy, Debug, Clone, PartialEq)]
pub enum FilterPolicyEntry {
None,
Bloom(BloomConstructionPolicy),
}
#[derive(Debug, Clone, PartialEq)]
pub struct FilterPolicy(Vec<FilterPolicyEntry>);
impl std::ops::Deref for FilterPolicy {
type Target = [FilterPolicyEntry];
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl FilterPolicy {
pub(crate) fn get(&self, level: usize) -> FilterPolicyEntry {
#[expect(clippy::expect_used, reason = "policy is expected not to be empty")]
self.0
.get(level)
.copied()
.unwrap_or_else(|| self.last().copied().expect("policy should not be empty"))
}
#[must_use]
pub fn disabled() -> Self {
Self::all(FilterPolicyEntry::None)
}
#[must_use]
pub fn all(c: FilterPolicyEntry) -> Self {
Self(vec![c])
}
#[must_use]
pub fn new(policy: impl Into<Vec<FilterPolicyEntry>>) -> Self {
let policy = policy.into();
assert!(!policy.is_empty(), "compression policy may not be empty");
assert!(policy.len() <= 255, "compression policy is too large");
Self(policy)
}
}