orx_tree/
node.rs

1use crate::{
2    TreeVariant,
3    aliases::Col,
4    memory::{Auto, MemoryPolicy},
5    node_ref::NodeRefCore,
6    pinned_storage::{PinnedStorage, SplitRecursive},
7};
8use orx_selfref_col::NodePtr;
9
10/// A node of the tree.
11pub struct Node<'a, V, M = Auto, P = SplitRecursive>
12where
13    V: TreeVariant,
14    M: MemoryPolicy,
15    P: PinnedStorage,
16{
17    col: &'a Col<V, M, P>,
18    node_ptr: NodePtr<V>,
19}
20
21// SAFETY: Required for enabling `NodeRef::walk_with_par`.
22// Notice that `Node` does not expose any methods other than implementing `NodeRef`,
23// and all node ref methods are thread safe without data race risks.
24unsafe impl<V, M, P> Send for Node<'_, V, M, P>
25where
26    V: TreeVariant,
27    M: MemoryPolicy,
28    P: PinnedStorage,
29    V::Item: Send,
30{
31}
32// SAFETY: Required for enabling `NodeRef::walk_with_par`.
33// Notice that `Node` does not expose any methods other than implementing `NodeRef`,
34// and all node ref methods are thread safe without data race risks.
35unsafe impl<V, M, P> Sync for Node<'_, V, M, P>
36where
37    V: TreeVariant,
38    M: MemoryPolicy,
39    P: PinnedStorage,
40    V::Item: Sync,
41{
42}
43
44impl<V, M, P> Clone for Node<'_, V, M, P>
45where
46    V: TreeVariant,
47    M: MemoryPolicy,
48    P: PinnedStorage,
49{
50    fn clone(&self) -> Self {
51        Self {
52            col: self.col,
53            node_ptr: self.node_ptr.clone(),
54        }
55    }
56}
57
58impl<'a, V, M, P> Node<'a, V, M, P>
59where
60    V: TreeVariant,
61    M: MemoryPolicy,
62    P: PinnedStorage,
63{
64    // helpers
65
66    pub(crate) fn new(col: &'a Col<V, M, P>, node_ptr: NodePtr<V>) -> Self {
67        Self { col, node_ptr }
68    }
69}
70
71impl<'a, V, M, P> NodeRefCore<'a, V, M, P> for Node<'a, V, M, P>
72where
73    V: TreeVariant,
74    M: MemoryPolicy,
75    P: PinnedStorage,
76{
77    #[inline(always)]
78    fn col(&self) -> &'a Col<V, M, P> {
79        self.col
80    }
81
82    #[inline(always)]
83    fn node_ptr(&self) -> &NodePtr<V> {
84        &self.node_ptr
85    }
86}