⎇ 1624a68d7a2e09de1c73f70dffa098e358793753
benches/helpers/mod.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
1#[cfg(feature = "yoga_benchmark")]
2mod yoga_helpers;
3
4/// A helper function to recursively construct a deep tree
5pub fn build_deep_tree<T, N>(
6 tree: &mut T,
7 max_nodes: u32,
8 branching_factor: u32,
9 create_leaf_node: &mut impl FnMut(&mut T) -> N,
10 create_container_node: &mut impl FnMut(&mut T, Vec<N>) -> N,
11) -> Vec<N> {
12 if max_nodes <= branching_factor {
13 // Build leaf nodes
14 return (0..max_nodes).map(|_| create_leaf_node(tree)).collect();
15 }
16
17 // Add another layer to the tree
18 // Each child gets an equal amount of the remaining nodes
19 (0..branching_factor)
20 .map(|_| {
21 let max_nodes = (max_nodes - branching_factor) / branching_factor;
22 let sub_children =
23 build_deep_tree(tree, max_nodes, branching_factor, create_leaf_node, create_container_node);
24 create_container_node(tree, sub_children)
25 })
26 .collect()
27}