graph/hierarchy_utils library
Hierarchy flattener and builder from flat list with parent ids — roadmap #556, #557.
Classes
- HierarchyUtils
- Node with id and optional parentId for tree building.
- HierarchyValidation
- Problem ids found by validateHierarchy.
Enums
- HierarchyCycleBreak
- How repairHierarchy breaks a parent cycle of two or more nodes.
Functions
-
flattenHierarchy(
List< HierarchyUtils> nodes) → List<(String, int)> -
Flattens tree:
nodeshas (id, parentId). Returns list of (id, level). Root level = 0. -
hierarchyFromParentIds(
List< HierarchyUtils> nodes) → Map<String, String?> - Builds a parent map from a flat list: id -> parentId.
-
repairHierarchy(
List< HierarchyUtils> nodes, {HierarchyCycleBreak cycleBreak = HierarchyCycleBreak.everyMember}) → List<HierarchyUtils> -
Returns a cleaned copy of
nodesthat validateHierarchy reports as valid and flattenHierarchy accepts.nodesis not modified. Runs in O(n). -
validateHierarchy(
List< HierarchyUtils> nodes) → HierarchyValidation -
Checks
nodesfor the problems that make flattenHierarchy throw, and returns them instead of throwing. Runs in O(n).