View Source MPTree (MPTree v0.1.1)

What is MPTT (Modified Preorder Tree Traversal?)

MPTree API

Link to this section Summary

Types

Used by insert, update, and fetch functions to find nodes.

t()

Updates a node

Functions

Find children of the node matching parent_fn

Find children of the node matching parent_fn.

Find descendents of the node matching ancestor_fn.

Find descendents of the node matching ancestor_fn.

Find parent of the node matching child_fn.

Find parent of the node matching child_fn.

Create a tree from a root_node.

Insert a node or tree as a new child of the node matching parent_fn.

Insert a node or tree as a new child of the node matching parent_fn.

Get all nodes.

Link to this section Types

Specs

match_fn() :: (MPTree.Node.t() -> as_boolean(any()))

Used by insert, update, and fetch functions to find nodes.

Beware, this will match only the first node it finds. If there any many nodes that might possibly pass the test, the results could be unpredictable.

Specs

t() :: %MPTree{nodes: [MPTree.Node.t(), ...]}

Specs

update_fn() :: (MPTree.Node.t() -> MPTree.Node.t())

Updates a node

Link to this section Functions

Link to this function

fetch_children(tree, parent_fn)

View Source

Specs

fetch_children(t(), match_fn()) :: {:ok, [MPTree.Node.t()]} | :error

Find children of the node matching parent_fn

Returns :error if no parent is found.

Link to this function

fetch_children!(tree, parent_fn)

View Source

Specs

fetch_children!(t(), match_fn()) :: [MPTree.Node.t()]

Find children of the node matching parent_fn.

Throws if no parent is found.

Link to this function

fetch_descendents(tree, ancestor_fn)

View Source

Specs

fetch_descendents(t(), match_fn()) :: {:ok, [MPTree.Node.t()]} | :error

Find descendents of the node matching ancestor_fn.

Returns :error if no ancestor is found.

Link to this function

fetch_descendents!(tree, ancestor_fn)

View Source

Specs

fetch_descendents!(t(), match_fn()) :: [MPTree.Node.t()]

Find descendents of the node matching ancestor_fn.

Throws if no ancestor is found.

Link to this function

fetch_parent(tree, child_fn)

View Source

Specs

fetch_parent(t(), match_fn()) :: {:ok, MPTree.Node.t()} | :error

Find parent of the node matching child_fn.

Returns :error if child is not found or if child is the root node.

Link to this function

fetch_parent!(tree, child_fn)

View Source

Specs

fetch_parent!(t(), match_fn()) :: MPTree.Node.t()

Find parent of the node matching child_fn.

Throws if child is not found or if child is the root node.

Specs

from_node(MPTree.Node.t()) :: t()

Create a tree from a root_node.

Link to this function

insert(tree, node_or_tree, parent_fn)

View Source

Specs

insert(t(), MPTree.Node.t() | t(), match_fn()) :: {:ok, t()} | :error

Insert a node or tree as a new child of the node matching parent_fn.

Returns :error if no existing node matches parent_fn

Link to this function

insert!(tree, node_or_tree, parent_fn)

View Source

Specs

insert!(t(), MPTree.Node.t() | t(), match_fn()) :: t()

Insert a node or tree as a new child of the node matching parent_fn.

Throws if no existing node matches parent_fn

Specs

nodes(t()) :: [MPTree.Node.t(), ...]

Get all nodes.

Link to this function

update_nodes(tree, update_fn)

View Source

Specs

update_nodes(t(), update_fn()) :: t()

Apply update_fn/0 to all nodes.

Link to this function

update_nodes(tree, update_fn, match_fn)

View Source

Specs

update_nodes(t(), update_fn(), match_fn()) :: t()

Apply update_fn/0 to all nodes matching the match_fn/0.