graphqexl v0.1.0-alpha-rc.11 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 type

collection()

collection() :: stack() | queue()
Link to this type

history()

history() :: [any()]
Link to this type

operation()

operation() :: (any(), any(), history() -> result())
Link to this type

queue()

queue() :: :queue.queue()
Link to this type

result()

result() :: {:continue, any()} | {:stop, any()}
Link to this type

stack()

stack() :: [tree()] | []
Link to this type

traverse()

traverse() :: :dfs | :bfs

Link to this section Functions

Link to this function

traverse(tree, operation, type)

traverse(tree(), operation(), traverse()) :: history()

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]