graphqexl v0.1.0-alpha-rc.14 Treex.Traverse
Basic tree traversal algoritms. It implements depth-first and breadth-first traverse algorithms
Link to this section Summary
Functions
Main function. You need to pass the tree structure, the function operation and the algorithm to use. An operation function must have the type: (any, any, history -> result) with the form: fn value, key, history -> body end where value and key are the node's values and keys, and history is the accumulated list of traverse operated nodes.
Link to this section Types
Link to this section Functions
traverse(tree, operation, type)
Main function. You need to pass the tree structure, the function operation and the algorithm to use. An operation function must have the type: (any, any, history -> result) with the form: fn value, key, history -> body end where value and key are the node's values and keys, and history is the accumulated list of traverse operated nodes.
Returns list with the result of the operation on each node
Examples
iex> Treex.TreeTraversal.traverse(nil, fn x, , -> {:continue, x} end, :bfs) []
iex> Treex ..(1)> .Traverse ..(1)> .traverse(%Treex.Tree{value: 1, ..(1)> children: [%Treex.Tree{value: 2}, ..(1)> %Treex.Tree{value: 3}, ..(1)> %Treex.Tree{value: 4}]}, ..(1)> fn x, , -> {:continue, x} end, ..(1)> :bfs) [4, 3, 2, 1]
tree_insert(collection, tree)
tree_insert(collection(), tree()) :: collection()