besmarts.core.trees module

besmarts.core.trees

Graphs with no cycles, a rough concept of directed edges, and have a root nodes

class besmarts.core.trees.tree_index[source]

Bases: object

A tree data structure that serves as a hierarchical index.

above: Dict[int, int]
below: Dict[int, List[int]]
copy()[source]
node_add(above_idx, tnode: tree_node, index=None) tree_node[source]
node_add_below(above_idx, index=None) tree_node[source]
node_remove(idx: int) tree_node[source]
node_remove_by_name(name: str) List[tree_node][source]
nodes: Dict[int, tree_node]
besmarts.core.trees.tree_index_copy(tree: tree_index)[source]
besmarts.core.trees.tree_index_node_add(tree: tree_index, above_idx, tnode: tree_node, index=None) tree_node[source]

Add a entry to the index.

Parameters:
  • up_idx (int) – The entry index that the incoming entry should be attached to

  • hent (hentry) – The entry to add

  • index (int) – The position to add the entry of the parent entry has existing children. A value of 0 will insert the new entry in front. A value of None will append the hentry at the end.

Returns:

The entry with a new index

Return type:

hentry

besmarts.core.trees.tree_index_node_depth(tree: tree_index, node: tree_node)[source]

Return the depth of the hentry in the hierarchical index.

Parameters:
  • tree (tree_index) – The input tree

  • node (tree_node) – The node to get the depth of

Returns:

The node depth.

Return type:

int

besmarts.core.trees.tree_index_node_remove(tree, idx)[source]

Remove an entry from the index and repair the hierarchy. The children of the entry are attached to the entry’s parent.

Parameters:

idx (int) – The index of the entry to remove

Returns:

The removed entry

Return type:

hentry

besmarts.core.trees.tree_index_node_remove_by_name(tree, name: str) List[tree_node][source]

Remove an entry from the index and repair the hierarchy. The children of the entry are attached to the entry’s parent.

Parameters:

idx (int) – The index of the entry to remove

Returns:

The removed entry

Return type:

hentry

besmarts.core.trees.tree_index_roots(t: tree_index)[source]
class besmarts.core.trees.tree_node(index, category, type, name)[source]

Bases: object

category: str
copy()[source]
index: int
name: str
type: str
besmarts.core.trees.tree_node_copy(n: tree_node)[source]