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 Default for BlockSizePolicy {
19 fn default() -> Self {
20 Self::new(&[4 * 1_024])
21 }
22}
23
24impl BlockSizePolicy {
25 pub(crate) fn get(&self, level: usize) -> u32 {
26 self.0
27 .get(level)
28 .copied()
29 .unwrap_or_else(|| self.last().copied().expect("policy should not be empty"))
30 }
31
32 #[must_use]
36 pub fn all(c: u32) -> Self {
37 Self(vec![c])
38 }
39
40 #[must_use]
42 pub fn new(policy: &[u32]) -> Self {
43 assert!(!policy.is_empty(), "compression policy may not be empty");
44 assert!(policy.len() <= 255, "compression policy is too large");
45 Self(policy.into())
46 }
47}