gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Sutichaykuna

⎇ 9e62e959cb49f18f8b452f0dd1a9c7adb8dd02cb benches/src/lib.rs Rust · 31 siq'ikuna · 1005 B Ñawpa willay Pi imata llamkarqan ch'uya

Fix yoga benchmark feature flag (#471) 129e31a56 · Nico Burns ·

1#[cfg(feature = "yoga")]
2pub mod yoga_helpers;
3
4mod random_style;
5pub use random_style::Randomizeable;
6
7/// A helper function to recursively construct a deep tree
8#[allow(dead_code)]
9pub fn build_deep_tree<T, N>(
10    tree: &mut T,
11    max_nodes: u32,
12    branching_factor: u32,
13    create_leaf_node: &mut impl FnMut(&mut T) -> N,
14    create_container_node: &mut impl FnMut(&mut T, Vec<N>) -> N,
15) -> Vec<N> {
16    if max_nodes <= branching_factor {
17        // Build leaf nodes
18        return (0..max_nodes).map(|_| create_leaf_node(tree)).collect();
19    }
20
21    // Add another layer to the tree
22    // Each child gets an equal amount of the remaining nodes
23    (0..branching_factor)
24        .map(|_| {
25            let max_nodes = (max_nodes - branching_factor) / branching_factor;
26            let sub_children =
27                build_deep_tree(tree, max_nodes, branching_factor, create_leaf_node, create_container_node);
28            create_container_node(tree, sub_children)
29        })
30        .collect()
31}