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))),
})),
}
}
}