1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::{
tree::{Item, Key, MessageRingBuffer},
Tree,
};
use dashmap::DashMap;
use parking_lot::Mutex;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub struct TreeOptions {
pub initial_capacity: usize,
pub message_buffer_capacity: usize,
}
impl TreeOptions {
pub fn create(self) -> Tree {
self.into()
}
}
impl Default for TreeOptions {
fn default() -> Self {
TreeOptions {
initial_capacity: 100,
message_buffer_capacity: 20,
}
}
}
impl From<TreeOptions> for Tree {
fn from(
TreeOptions {
initial_capacity,
message_buffer_capacity,
}: TreeOptions,
) -> Self {
Tree {
inner: Arc::new(Mutex::new(Item {
highest_child_id: 0,
key: Key::default(),
tree: Arc::new(DashMap::with_capacity(initial_capacity)),
messages: Arc::new(Mutex::new(MessageRingBuffer::with_capacity(
message_buffer_capacity,
))),
})),
}
}
}