rockpool.utilities.tree_utils

Tree manipulation utilities with no external dependencies

This module provides methods for building and manipulating trees.

A Tree is a nested dictionary. A Leaf is any other object. A Node is a non-leaf Tree node. A TreeDef is a nested dictionary with no data, only structure.

Functions

branches(tree[, prefix])

Generate all branches (paths from root node to any leaf) in a tree

get_nested(tree, branch)

Get a value from a tree branch, specifying a branch

make_prototype_tree(full_tree, target_tree)

Construct a tree with boolean leaves, for nodes that match a target tree

set_matching(full_tree, target_tree, value)

Set the values in a full tree, for branches that match a target tree

set_matching_select(full_tree, target_tree, ...)

Set the values in a full tree, for branches that match a target tree, if the target tree leaf nodes evaluate to True

set_nested(tree, branch, value[, inplace])

Set a value in a tree branch, specifying a branch

tree_find(tree)

Generate the tree branches to tree nodes that evaluate to True

tree_flatten(tree[, leaves])

Flatten a tree into a linear list of leaf nodes and a tree description

tree_map(tree, f)

Map a function over the leaves of a tree

tree_unflatten(treedef, leaves[, leaves_tail])

Build a tree from a flat list of leaves, plus a tree definition

tree_update(target, additional[, inplace])

Perform a recursive update of a tree to insert or replace nodes from a second tree