1use serde::Deserialize;
5
6use std::num::NonZeroUsize;
7
8const DEFAULT_BELOW_MAX_DEPTH: u32 = 15;
9const DEFAULT_NUM_PARTITIONS: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(16) };
11const DEFAULT_MAX_EVICTION_RETRIES: usize = 10;
12
13#[derive(Default, Deserialize)]
15pub struct TangleConfigBuilder {
16 below_max_depth: Option<u32>,
17 num_partitions: Option<NonZeroUsize>,
18 max_eviction_retries: Option<usize>,
19}
20
21impl TangleConfigBuilder {
22 pub fn new() -> Self {
24 Self::default()
25 }
26
27 pub fn finish(self) -> TangleConfig {
29 TangleConfig {
30 below_max_depth: self.below_max_depth.unwrap_or(DEFAULT_BELOW_MAX_DEPTH),
31 num_partitions: self.num_partitions.unwrap_or(DEFAULT_NUM_PARTITIONS),
32 max_eviction_retries: self.max_eviction_retries.unwrap_or(DEFAULT_MAX_EVICTION_RETRIES),
33 }
34 }
35}
36
37#[derive(Clone)]
39pub struct TangleConfig {
40 below_max_depth: u32,
41 num_partitions: NonZeroUsize,
42 max_eviction_retries: usize,
43}
44
45impl TangleConfig {
46 pub fn build() -> TangleConfigBuilder {
48 TangleConfigBuilder::new()
49 }
50
51 pub fn below_max_depth(&self) -> u32 {
53 self.below_max_depth
54 }
55
56 pub fn num_partitions(&self) -> NonZeroUsize {
58 self.num_partitions
59 }
60
61 pub fn max_eviction_retries(&self) -> usize {
63 self.max_eviction_retries
64 }
65}