tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1118HTML 1044Markdown 12TOML 94781 Definiciones

⎇ 2b5366e4296fc2a5d84bfd8bc6967939a815c154 benches/src/lib.rs Rust · 31 líneas · 1015 B Historia Quién tocó qué crudo

Move benchmarks into their own crate (#451) 2b5366e42 · Nico Burns ·

1#[cfg(feature = "yoga_benchmark")]
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}