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