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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
pub const
/// Join two paths into a single path.
/// This will allocate
// impl AsNodePath for NodePath {
// fn split_parent(&self) -> Option<(&[u16], usize)> {
// self.split()
// }
// fn pop(&self) -> Option<&[u16]> {
// self.as_slice().pop()
// }
// }
// /// Node path indicates where in the tree a node is.
// /// The node path can change through a values life time,
// /// unlike the value key it self.
// #[derive(Debug, Clone, PartialEq)]
// pub struct NodePath(Box<[u16]>);
// impl NodePath {
// pub fn root() -> Self {
// Self(Box::new([]))
// }
// pub fn contains(&self, other: &Self) -> bool {
// let len = self.0.len().min(other.0.len());
// self.0[..len] == other.0[..len]
// }
// pub fn reparent(&mut self, new_parent: &NodePath) {
// debug_assert!(new_parent.0.len() <= self.0.len());
// self.0[..new_parent.0.len()].copy_from_slice(&new_parent.0);
// }
// pub fn split(&self) -> Option<(&[u16], usize)> {
// match self.as_slice() {
// [] => None,
// [i] => Some((&[], *i as usize)),
// [parent @ .., i] => Some((parent, *i as usize)),
// }
// }
// pub fn as_slice(&self) -> &[u16] {
// &self.0
// }
// pub fn as_slice_mut(&mut self) -> &mut [u16] {
// &mut self.0
// }
// }
// impl Deref for NodePath {
// type Target = [u16];
// fn deref(&self) -> &Self::Target {
// self.as_slice()
// }
// }
// impl Default for NodePath {
// fn default() -> Self {
// NodePath::root()
// }
// }
// impl Add<u16> for &NodePath {
// type Output = NodePath;
// fn add(self, rhs: u16) -> Self::Output {
// let mut node_id = Vec::with_capacity(self.0.len() + 1);
// node_id.extend_from_slice(&self.0);
// node_id.push(rhs);
// NodePath(node_id.into_boxed_slice())
// }
// }
// impl From<(&[u16], usize)> for NodePath {
// fn from((root, index): (&[u16], usize)) -> Self {
// let mut path = Vec::with_capacity(root.len() + 1);
// path.extend_from_slice(root);
// path.push(index as u16);
// Self(path.into_boxed_slice())
// }
// }
// impl From<&[u16]> for NodePath {
// fn from(root: &[u16]) -> Self {
// Self(root.to_vec().into_boxed_slice())
// }
// }
// impl<const N: usize> From<[u16; N]> for NodePath {
// fn from(value: [u16; N]) -> Self {
// NodePath(Box::new(value))
// }
// }