lsm_tree/config/
filter.rs1pub use crate::table::filter::BloomConstructionPolicy;
6
7#[derive(Copy, Debug, Clone, PartialEq)]
11pub enum FilterPolicyEntry {
12 None,
14
15 Bloom(BloomConstructionPolicy),
17}
18
19#[derive(Debug, Clone, PartialEq)]
21pub struct FilterPolicy(Vec<FilterPolicyEntry>);
22
23impl std::ops::Deref for FilterPolicy {
24 type Target = [FilterPolicyEntry];
25
26 fn deref(&self) -> &Self::Target {
27 &self.0
28 }
29}
30
31impl FilterPolicy {
32 pub(crate) fn get(&self, level: usize) -> FilterPolicyEntry {
33 #[expect(clippy::expect_used, reason = "policy is expected not to be empty")]
34 self.0
35 .get(level)
36 .copied()
37 .unwrap_or_else(|| self.last().copied().expect("policy should not be empty"))
38 }
39
40 #[must_use]
44 pub fn disabled() -> Self {
45 Self::all(FilterPolicyEntry::None)
46 }
47
48 #[must_use]
50 pub fn all(c: FilterPolicyEntry) -> Self {
51 Self(vec![c])
52 }
53
54 #[must_use]
60 pub fn new(policy: impl Into<Vec<FilterPolicyEntry>>) -> Self {
61 let policy = policy.into();
62 assert!(!policy.is_empty(), "compression policy may not be empty");
63 assert!(policy.len() <= 255, "compression policy is too large");
64 Self(policy)
65 }
66}