Bintree (bintree v1.1.1) View Source
Basic module
Link to this section Summary
Types
Binary tree with left and right branch
Branch can be nil or other bintree
Currently only integers are supported as a value
Functions
Filters the bintree
, i.e. returns only those branch for which filter_fun
returns a truthy value.
Inserts a value
at a given path
Creates base binary tree
Automatically generates binary tree values
Formats the type of a binary tree to a string
Link to this section Types
Link to this section Functions
Specs
filter(branch(), filter_fun()) :: branch()
Filters the bintree
, i.e. returns only those branch for which filter_fun
returns a truthy value.
Specs
Inserts a value
at a given path
Example
iex> Bintree.new(1, 3, 5)
iex> |> Bintree.insert([:left, :left], 5)
iex> |> Bintree.insert([:left, :right], 28)
# Result:
# 1
# |
# /---\
# | |
# 3 5
# |
# /--\
# | |
# 5 28
Specs
Creates base binary tree
Specs
new(any(), process_fun(), process_fun(), filter_fun() | non_neg_integer()) :: branch()
Automatically generates binary tree values
Generates a branch while the filter_fun returns a truthy value.
Examples
iex> Bintree.new(1, &(&1*3), &(&1+3), &(&1 > 10))
# Returns a binary tree, where turning left is multiplying by three,
# turning right is adding three. If the number is greater than 10,
# then the generation of this branch is stopped.
iex> Bintree.new(1, &(&1*3), &(&1+3), 4)
# The rules are the same as the previous one, but the generation of the tree will end
# when the depth of 4 values is reached.
Specs
Formats the type of a binary tree to a string