View Source MPTree (MPTree v0.1.1)
What is MPTT (Modified Preorder Tree Traversal?)
- https://imrannazar.com/Modified-Preorder-Tree-Traversal
- https://www.atlantis-press.com/article/125938811.pdf
- https://gist.github.com/tmilos/f2f999b5839e2d42d751
MPTree
API
Link to this section Summary
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.
Apply update_fn/0
to all nodes.
Apply update_fn/0
to all nodes matching the match_fn/0
.
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
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.
Specs
fetch_children!(t(), match_fn()) :: [MPTree.Node.t()]
Find children of the node matching parent_fn
.
Throws if no parent is found.
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.
Specs
fetch_descendents!(t(), match_fn()) :: [MPTree.Node.t()]
Find descendents of the node matching ancestor_fn
.
Throws if no ancestor is found.
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.
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
.
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
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.
Specs
Apply update_fn/0
to all nodes.
Specs
Apply update_fn/0
to all nodes matching the match_fn/0
.