lsm_tree/config/
hash_ratio.rs1#[derive(Debug, Clone, PartialEq)]
7pub struct HashRatioPolicy(Vec<f32>);
8
9impl std::ops::Deref for HashRatioPolicy {
10 type Target = [f32];
11
12 fn deref(&self) -> &Self::Target {
13 &self.0
14 }
15}
16
17impl HashRatioPolicy {
18 pub(crate) fn get(&self, level: usize) -> f32 {
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]
27 pub fn all(c: f32) -> Self {
28 Self(vec![c])
29 }
30
31 #[must_use]
33 pub fn new(policy: impl Into<Vec<f32>>) -> Self {
34 let policy = policy.into();
35 assert!(!policy.is_empty(), "compression policy may not be empty");
36 assert!(policy.len() <= 255, "compression policy is too large");
37 Self(policy)
38 }
39}