orx_tree/subtrees/
moved_subtree.rs

1use super::subtree::sealed::SubTreeCore;
2use crate::{
3    Dfs, MemoryPolicy, NodeMut, NodeMutOrientation, NodeRef, TreeVariant,
4    node_ref::NodeRefCore,
5    pinned_storage::PinnedStorage,
6    traversal::{OverDepthData, traverser_core::TraverserCore},
7};
8use orx_selfref_col::NodePtr;
9
10pub struct MovedSubTree<'a, V, M, P, MO>
11where
12    V: TreeVariant + 'a,
13    M: MemoryPolicy,
14    P: PinnedStorage,
15    MO: NodeMutOrientation,
16{
17    node: NodeMut<'a, V, M, P, MO>,
18}
19
20impl<'a, V, M, P, MO> MovedSubTree<'a, V, M, P, MO>
21where
22    V: TreeVariant + 'a,
23    M: MemoryPolicy,
24    P: PinnedStorage,
25    MO: NodeMutOrientation,
26{
27    pub(crate) fn new(node: NodeMut<'a, V, M, P, MO>) -> Self {
28        Self { node }
29    }
30}
31
32impl<'a, V, M, P, MO> SubTreeCore<V> for MovedSubTree<'a, V, M, P, MO>
33where
34    V: TreeVariant + 'a,
35    M: MemoryPolicy,
36    P: PinnedStorage,
37    MO: NodeMutOrientation,
38{
39    fn root_ptr(&self) -> NodePtr<V> {
40        self.node.node_ptr().clone()
41    }
42
43    fn root_parent_ptr(&self) -> Option<NodePtr<V>> {
44        self.node.parent_ptr()
45    }
46
47    fn root_sibling_idx(&self) -> usize {
48        self.node.sibling_idx()
49    }
50
51    fn create_subtree(&mut self) -> impl IntoIterator<Item = (usize, <V>::Item)> {
52        let node = unsafe { self.node.clone_node_mut() };
53        Dfs::<OverDepthData>::into_iter_with_owned_storage(node)
54    }
55}