[−][src]Function sharpen::tree_rollup::rollup_tree
pub fn rollup_tree<T, I>(
input: I,
mapping: &BTreeMap<usize, usize>
) -> Option<impl Iterator<Item = T>> where
T: Node,
I: IntoIterator<Item = T>,
Roll up a tree given as a flat structure and a mapping {from child to parent} into a hierarchical structure.
Invariants for the arguments:
- The largest index in
mapping
should be inside of the bounds ofinput
. - This means that any parent must come before it's children inside
input
.
Return value:
- None: Detected duplicated usage of id's (probably the
mapping
was invalid). - Some(collected): The rolled-up tree, with only top-level children left at top-level.