orx_tree/traversal/
node_item.rs1use crate::Node;
2use crate::TreeVariant;
3use crate::aliases::Col;
4use crate::memory::{Auto, MemoryPolicy};
5use crate::pinned_storage::{PinnedStorage, SplitRecursive};
6use orx_selfref_col::NodePtr;
7
8pub trait NodeItem<'a, V, M = Auto, P = SplitRecursive>
9where
10 V: TreeVariant,
11 M: MemoryPolicy,
12 P: PinnedStorage,
13{
14 fn from_ptr(col: &'a Col<V, M, P>, node_ptr: NodePtr<V>) -> Self;
15
16 #[cfg(test)]
17 fn node_data(&self) -> &V::Item;
18}
19
20impl<'a, V, M, P> NodeItem<'a, V, M, P> for Node<'a, V, M, P>
21where
22 V: TreeVariant,
23 M: MemoryPolicy,
24 P: PinnedStorage,
25{
26 #[inline(always)]
27 fn from_ptr(col: &'a Col<V, M, P>, node_ptr: NodePtr<V>) -> Self {
28 Node::new(col, node_ptr)
29 }
30
31 #[cfg(test)]
32 #[inline(always)]
33 fn node_data(&self) -> &V::Item {
34 use crate::NodeRef;
35 self.data()
36 }
37}
38
39impl<'a, V, M, P> NodeItem<'a, V, M, P> for &'a V::Item
40where
41 V: TreeVariant,
42 M: MemoryPolicy,
43 P: PinnedStorage,
44{
45 #[inline(always)]
46 fn from_ptr(_: &'a Col<V, M, P>, node_ptr: NodePtr<V>) -> Self {
47 let node = unsafe { &*node_ptr.ptr() };
48 node.data().expect("active tree node has data")
49 }
50
51 #[cfg(test)]
52 #[inline(always)]
53 fn node_data(&self) -> &V::Item {
54 self
55 }
56}
57
58impl<'a, V, M, P> NodeItem<'a, V, M, P> for NodePtr<V>
59where
60 V: TreeVariant,
61 M: MemoryPolicy,
62 P: PinnedStorage,
63{
64 #[inline(always)]
65 fn from_ptr(_: &'a Col<V, M, P>, node_ptr: NodePtr<V>) -> Self {
66 node_ptr
67 }
68
69 #[cfg(test)]
70 #[inline(always)]
71 fn node_data(&self) -> &V::Item {
72 unsafe { &*self.ptr() }
73 .data()
74 .expect("active tree node has data")
75 }
76}