orx_tree/traversal/post_order/
iter_ref.rs1use super::iter_ptr::Item;
2use super::iter_ptr::PostOrderIterPtr;
3use super::post_enumeration::PostOrderEnumeration;
4use super::states::State;
5use crate::TreeVariant;
6use crate::aliases::Col;
7use crate::memory::MemoryPolicy;
8use crate::pinned_storage::PinnedStorage;
9use crate::traversal::node_item::NodeItem;
10use alloc::vec::Vec;
11use core::marker::PhantomData;
12use orx_self_or::SoM;
13
14pub struct PostOrderIterRef<'a, V, M, P, E, S, D>
15where
16 V: TreeVariant,
17 M: MemoryPolicy,
18 P: PinnedStorage,
19 E: PostOrderEnumeration,
20 S: SoM<Vec<State<V>>>,
21 D: NodeItem<'a, V, M, P>,
22{
23 col: &'a Col<V, M, P>,
24 iter: PostOrderIterPtr<V, E, S>,
25 phantom: PhantomData<D>,
26}
27
28impl<'a, V, M, P, E, S, D> From<(&'a Col<V, M, P>, PostOrderIterPtr<V, E, S>)>
29 for PostOrderIterRef<'a, V, M, P, E, S, D>
30where
31 V: TreeVariant,
32 M: MemoryPolicy,
33 P: PinnedStorage,
34 E: PostOrderEnumeration,
35 S: SoM<Vec<State<V>>>,
36 D: NodeItem<'a, V, M, P>,
37{
38 fn from((col, iter): (&'a Col<V, M, P>, PostOrderIterPtr<V, E, S>)) -> Self {
39 Self {
40 col,
41 iter,
42 phantom: PhantomData,
43 }
44 }
45}
46
47impl<'a, V, M, P, E, D> Clone for PostOrderIterRef<'a, V, M, P, E, Vec<State<V>>, D>
48where
49 V: TreeVariant,
50 M: MemoryPolicy,
51 P: PinnedStorage,
52 E: PostOrderEnumeration,
53 D: NodeItem<'a, V, M, P>,
54 Item<V, E>: Clone,
55{
56 fn clone(&self) -> Self {
57 Self {
58 col: self.col,
59 iter: self.iter.clone(),
60 phantom: self.phantom,
61 }
62 }
63}
64
65impl<'a, V, M, P, E, S, D> Iterator for PostOrderIterRef<'a, V, M, P, E, S, D>
66where
67 V: TreeVariant,
68 M: MemoryPolicy,
69 P: PinnedStorage,
70 E: PostOrderEnumeration,
71 S: SoM<Vec<State<V>>>,
72 D: NodeItem<'a, V, M, P>,
73{
74 type Item = E::Item<D>;
75
76 fn next(&mut self) -> Option<Self::Item> {
77 self.iter
78 .next()
79 .map(|element: Item<V, E>| E::from_element_ptr(self.col, element))
80 }
81}