orx_tree/traversal/factory.rs
1use super::{breadth_first::Bfs, depth_first::Dfs, post_order::PostOrder};
2
3/// Type with methods allowing to create different [`Traverser`] types with
4/// different walk strategies, such as depth-first, breadth-first or post-order.
5///
6/// [`Traverser`]: crate::traversal::Traverser
7#[derive(Clone, Copy)]
8pub struct Traversal;
9
10impl Traversal {
11 /// Creates the default (pre-order) depth-first-search traverser
12 /// ([Wikipedia](https://en.wikipedia.org/wiki/Depth-first_search)).
13 ///
14 /// The default traverser creates iterators that yield references or mutable references
15 /// to the node data; i.e., [`OverData`].
16 ///
17 /// However, item type of the iterators that the traverser creates can be transformed
18 /// any time using the transformation methods:
19 ///
20 /// * [`over_data`]
21 /// * [`over_nodes`]
22 /// * [`with_depth`]
23 /// * [`with_sibling_idx`]
24 ///
25 /// [`OverData`]: crate::traversal::OverData
26 /// [`over_data`]: crate::traversal::Traverser::over_data
27 /// [`over_nodes`]: crate::traversal::Traverser::over_nodes
28 /// [`with_depth`]: crate::traversal::Traverser::with_depth
29 /// [`with_sibling_idx`]: crate::traversal::Traverser::with_sibling_idx
30 pub fn dfs(self) -> Dfs {
31 Default::default()
32 }
33
34 /// Creates the default breadth-first-search traverser, also known as level-order
35 /// ([wikipedia](https://en.wikipedia.org/wiki/Tree_traversal#Breadth-first_search))
36 ///
37 /// The default traverser creates iterators that yield references or mutable references
38 /// to the node data; i.e., [`OverData`].
39 ///
40 /// However, item type of the iterators that the traverser creates can be transformed
41 /// any time using the transformation methods:
42 ///
43 /// * [`over_data`]
44 /// * [`over_nodes`]
45 /// * [`with_depth`]
46 /// * [`with_sibling_idx`]
47 ///
48 /// [`OverData`]: crate::traversal::OverData
49 /// [`over_data`]: crate::traversal::Traverser::over_data
50 /// [`over_nodes`]: crate::traversal::Traverser::over_nodes
51 /// [`with_depth`]: crate::traversal::Traverser::with_depth
52 /// [`with_sibling_idx`]: crate::traversal::Traverser::with_sibling_idx
53 pub fn bfs(self) -> Bfs {
54 Default::default()
55 }
56
57 /// Creates the default post-order traverser
58 /// ([Wikipedia](https://en.wikipedia.org/wiki/Tree_traversal#Post-order,_LRN)).
59 ///
60 /// The default traverser creates iterators that yield references or mutable references
61 /// to the node data; i.e., [`OverData`].
62 ///
63 /// However, item type of the iterators that the traverser creates can be transformed
64 /// any time using the transformation methods:
65 ///
66 /// * [`over_data`]
67 /// * [`over_nodes`]
68 /// * [`with_depth`]
69 /// * [`with_sibling_idx`]
70 ///
71 /// [`OverData`]: crate::traversal::OverData
72 /// [`over_data`]: crate::traversal::Traverser::over_data
73 /// [`over_nodes`]: crate::traversal::Traverser::over_nodes
74 /// [`with_depth`]: crate::traversal::Traverser::with_depth
75 /// [`with_sibling_idx`]: crate::traversal::Traverser::with_sibling_idx
76 pub fn post_order(self) -> PostOrder {
77 Default::default()
78 }
79}