Skip to content

Commit e430ed4

Browse files
committed
recursive set is added to the example
1 parent 23fd148 commit e430ed4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

examples/mutable_traversal.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Display;
33

44
const INPUTS_COUNT: usize = 2;
55

6-
#[derive(Debug)]
6+
#[derive(Debug, Clone, Copy)]
77
enum Instruction {
88
Input(usize),
99
Add,
@@ -145,7 +145,34 @@ fn impl_over_children_mut() {
145145
println!("After execute:\n{}\n", &tree.tree);
146146
}
147147

148+
fn impl_recursive_set() {
149+
let inputs = [10.0, 20.0];
150+
151+
let mut tree = MyTree::example();
152+
153+
println!("\n\n# IMPL WITH RECURSIVE_SET");
154+
println!("\ninputs = {:?}\n", &inputs);
155+
println!("Before execute:\n{}\n", &tree.tree);
156+
157+
tree.tree
158+
.root_mut()
159+
.recursive_set(|node_data, children_data| {
160+
let instruction = node_data.instruction;
161+
let children_sum: f32 = children_data.iter().map(|x| x.value).sum();
162+
let value = match node_data.instruction {
163+
Instruction::Input(i) => inputs[i],
164+
Instruction::Add => children_sum,
165+
Instruction::AddI { val } => val + children_sum,
166+
};
167+
168+
InstructionNode { instruction, value }
169+
});
170+
171+
println!("After execute:\n{}\n", &tree.tree);
172+
}
173+
148174
fn main() {
149175
impl_over_children_idx();
150176
impl_over_children_mut();
177+
impl_recursive_set();
151178
}

src/traversal/post_order/traverser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use core::marker::PhantomData;
1313
/// # Construction
1414
///
1515
/// A post order traverser can be created,
16+
///
1617
/// * either by using Default trait and providing its two generic type parameters
1718
/// * `PostOrder::<_, OverData>::default()` or `PostOrder::<_, OverDepthSiblingIdxData>::default()`, or
1819
/// * `PostOrder::<Dyn<u64>, OverData>::default()` or `PostOrder::<Dary<2, String>, OverDepthSiblingIdxData>::default()`

0 commit comments

Comments
 (0)