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