orx_tree/traversal/post_order/traverser.rs
1use super::states::States;
2use crate::traversal::{
3 Traverser,
4 over::{Over, OverData},
5};
6use core::marker::PhantomData;
7
8/// A post order traverser ([Wikipedia](https://en.wikipedia.org/wiki/Tree_traversal#Post-order,_LRN)).
9///
10/// A traverser can be created once and used to traverse over trees multiple times without
11/// requiring additional memory allocation.
12///
13/// # Construction
14///
15/// A post order traverser can be created,
16///
17/// * either by using Default trait and providing its two generic type parameters
18/// * `PostOrder::<_, OverData>::default()` or `PostOrder::<_, OverDepthSiblingIdxData>::default()`, or
19/// * `PostOrder::<Dyn<u64>, OverData>::default()` or `PostOrder::<Dary<2, String>, OverDepthSiblingIdxData>::default()`
20/// if we want the complete type signature.
21/// * or by using the [`Traversal`] type.
22/// * `Traversal.post_order()` or `Traversal.post_order().with_depth().with_sibling_idx()`.
23///
24/// [`Traversal`]: crate::Traversal
25pub struct PostOrder<O = OverData>
26where
27 O: Over,
28{
29 pub(super) states: States,
30 phantom: PhantomData<O>,
31}
32
33impl Default for PostOrder {
34 fn default() -> Self {
35 Self::new()
36 }
37}
38
39impl<O> Traverser<O> for PostOrder<O>
40where
41 O: Over,
42{
43 type IntoOver<O2>
44 = PostOrder<O2>
45 where
46 O2: Over;
47
48 fn new() -> Self {
49 Self {
50 states: Default::default(),
51 phantom: PhantomData,
52 }
53 }
54
55 fn transform_into<O2: Over>(self) -> Self::IntoOver<O2> {
56 PostOrder {
57 states: self.states,
58 phantom: PhantomData,
59 }
60 }
61}