lsm_tree/config/
pinning.rs1#[derive(Debug, Clone, Eq, PartialEq)]
7pub struct PinningPolicy(Vec<bool>);
8
9impl std::ops::Deref for PinningPolicy {
10 type Target = [bool];
11
12 fn deref(&self) -> &Self::Target {
13 &self.0
14 }
15}
16
17impl PinningPolicy {
18 pub(crate) fn get(&self, level: usize) -> bool {
19 self.0
20 .get(level)
21 .copied()
22 .unwrap_or_else(|| self.last().copied().expect("policy should not be empty"))
23 }
24
25 #[must_use]
29 pub fn all(c: bool) -> Self {
30 Self(vec![c])
31 }
32
33 #[must_use]
35 pub fn new(policy: &[bool]) -> Self {
36 assert!(!policy.is_empty(), "compression policy may not be empty");
37 assert!(policy.len() <= 255, "compression policy is too large");
38 Self(policy.into())
39 }
40}