bitstring_trees/tree/mut_borrowed/
walk.rs1use crate::{
2 tree::{
3 mut_gen::{
4 Borrowed,
5 WalkMut,
6 WalkMutPath,
7 },
8 InsertPosition,
9 Node,
10 TreeProperties,
11 WalkedDirection,
12 },
13 walk_mut::NodeOrTree,
14};
15
16use super::{
17 IterMutBorrowedInOrder,
18 IterMutBorrowedLeaf,
19 IterMutBorrowedLeafFull,
20 IterMutBorrowedPostOrder,
21 IterMutBorrowedPreOrder,
22};
23
24pub struct WalkMutBorrowed<'r, TP: TreeProperties + 'r, D = (), A = ()> {
30 pub(in crate::tree) inner: WalkMut<'r, TP, Borrowed, D, A>,
31}
32
33impl<'r, TP, D, A> WalkMutBorrowed<'r, TP, D, A>
34where
35 TP: TreeProperties,
36{
37 pub fn up(&mut self) -> Option<D> {
39 self.inner.up()
40 }
41
42 pub fn up_with(&mut self) -> Option<(D, A)> {
44 self.inner.up_with()
45 }
46
47 pub fn current(&self) -> NodeOrTree<Option<&Node<TP>>, &Node<TP>> {
49 self.inner.current()
50 }
51
52 pub fn current_mut(&mut self) -> NodeOrTree<Option<&mut Node<TP>>, &mut Node<TP>> {
58 self.inner.current_mut()
59 }
60
61 pub fn into_current_mut(self) -> NodeOrTree<Option<&'r mut Node<TP>>, &'r mut Node<TP>> {
67 self.inner.into_current_mut()
68 }
69}
70
71impl<'r, TP, D, A> WalkMutBorrowed<'r, TP, D, A>
72where
73 TP: TreeProperties + 'r,
74 D: From<WalkedDirection>,
75{
76 pub fn down_root_with(&mut self, add: A) -> bool {
78 self.inner.down_root_with(add)
79 }
80
81 pub fn down_left_with(&mut self, add: A) -> bool {
83 self.inner.down_left_with(add)
84 }
85
86 pub fn down_right_with(&mut self, add: A) -> bool {
88 self.inner.down_right_with(add)
89 }
90
91 pub fn down_with(&mut self, side: bool, add: A) -> bool {
95 self.inner.down_with(side, add)
96 }
97}
98
99impl<'r, TP, D> WalkMutBorrowed<'r, TP, D, ()>
100where
101 TP: TreeProperties + 'r,
102 D: From<WalkedDirection>,
103{
104 pub fn down_root(&mut self) -> bool {
106 self.inner.down_root()
107 }
108
109 pub fn down_left(&mut self) -> bool {
111 self.inner.down_left()
112 }
113
114 pub fn down_right(&mut self) -> bool {
116 self.inner.down_right()
117 }
118
119 pub fn down(&mut self, side: bool) -> bool {
123 self.inner.down(side)
124 }
125}
126
127impl<'r, TP, D> WalkMutBorrowed<'r, TP, D>
128where
129 TP: TreeProperties + 'r,
130 D: From<WalkedDirection>,
131{
132 pub fn path(&mut self, key: TP::Key) -> WalkMutBorrowedPath<'r, '_, TP, D> {
139 WalkMutBorrowedPath {
140 inner: self.inner.path(key),
141 }
142 }
143
144 pub fn goto_insert(&mut self, key: &TP::Key) -> Option<InsertPosition> {
148 self.inner.goto_insert(key)
149 }
150}
151
152impl<'r, TP> WalkMutBorrowed<'r, TP, WalkedDirection, ()>
153where
154 TP: TreeProperties + 'r,
155{
156 pub fn into_iter_pre_order(self) -> IterMutBorrowedPreOrder<'r, TP> {
158 self.inner.into_iter_pre_order().into()
159 }
160
161 pub fn next_pre_order(&mut self) -> Option<&mut Node<TP>> {
163 self.inner.next_pre_order()
164 }
165
166 pub fn into_iter_in_order(self) -> IterMutBorrowedInOrder<'r, TP> {
168 self.inner.into_iter_in_order().into()
169 }
170
171 pub fn next_in_order(&mut self) -> Option<&mut Node<TP>> {
173 self.inner.next_in_order()
174 }
175
176 pub fn into_iter_post_order(self) -> IterMutBorrowedPostOrder<'r, TP> {
178 self.inner.into_iter_post_order().into()
179 }
180
181 pub fn next_post_order(&mut self) -> Option<&mut Node<TP>> {
183 self.inner.next_post_order()
184 }
185
186 pub fn into_iter_leafs(self) -> IterMutBorrowedLeaf<'r, TP> {
188 self.inner.into_iter_leafs().into()
189 }
190
191 pub fn into_iter_full_leafs(self) -> IterMutBorrowedLeafFull<'r, TP> {
193 self.inner.into_iter_full_leafs().into()
194 }
195
196 pub fn next_leaf(&mut self) -> Option<&mut Node<TP>> {
198 self.inner.next_leaf()
199 }
200}
201
202pub struct WalkMutBorrowedPath<'r, 'w, TP, D = ()>
204where
205 TP: TreeProperties + 'r,
206{
207 inner: WalkMutPath<'r, 'w, TP, Borrowed, D>,
208}
209
210impl<'r, 'w, TP, D> WalkMutBorrowedPath<'r, 'w, TP, D>
211where
212 TP: TreeProperties + 'r,
213 D: From<WalkedDirection>,
214{
215 #[allow(clippy::should_implement_trait)] pub fn next(&mut self) -> Option<&mut Node<TP>> {
218 self.inner.next()
219 }
220}
221
222