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
use crate::regex_radix_tree::{NodeItem, Storage, Trace};
use std::fmt::Debug;
pub trait Node<T: NodeItem, S: Storage<T>>: Debug + Send + Sync {
/// Insert a new item into this node
fn insert(&mut self, item: T, parent_prefix_size: u32);
/// Find storage associated to this value
fn find(&self, value: &str) -> Vec<&S>;
/// Traces when finding a value
fn trace(&self, value: &str) -> Trace<T, S>;
/// Remove an item on this tree
///
/// This method returns true if there is no more data so it can be cleaned up
fn remove(&mut self, id: &str) -> bool;
/// Return regex used by this node
fn regex(&self) -> &str;
/// Length of node
fn len(&self) -> usize;
/// Is node empty
fn is_empty(&self) -> bool;
fn can_insert_item(&self, prefix: &str, item: &T) -> bool;
/// Incr level of node by one
fn incr_level(&mut self);
/// Cache current regex according to a limit and a level
///
/// This method must return new limit of element cached (passed limit minus number of element cached)
/// which allow other node to avoid caching extra node
///
/// Implementation must not cache item if limit is equal to 0
/// Implementation must not cache item if not caching on the current node level
///
/// Level argument allow to build cache on first level of the tree by priority
/// Implementation must retain at which level this node is build and not do any caching
/// if we are not on the current level
fn cache(&mut self, limit: u64, level: u64) -> u64;
/// Allow to clone object
fn box_clone(&self) -> Box<dyn Node<T, S>>;
}
impl<T: NodeItem, S: Storage<T>> Clone for Box<dyn Node<T, S>> {
fn clone(&self) -> Self {
self.box_clone()
}
}