graphqexl v0.1.0-alpha-rc.25 Treex.Traverse

Basic tree traversal algorithms, implementing depth-first and breadth-first traversal.

Link to this section Summary

Functions

Traverse the given tree and invoke the given operation function on each node. The function operation and the algorithm to use (one of :bfs or :dfs).

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() :: (tree(), 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, atom)

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

Traverse the given tree and invoke the given operation function on each node. The function operation and the algorithm to use (one of :bfs or :dfs).

An operation function must have the type: (t:Treex.Tree.t/0, t:Treex.Tree.history -> t:Treex.Tree.result/0) with the form: fn node, history -> body end where node is the current node and history is the accumulated list of traverse operated nodes.

Returns: [t:Treex.Tree.result/0]

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]