Zippy v0.0.1 Zippy.ZBinTree

This module implements Zipper binary trees, that allow you to traverse them in two directions.

This module is a port of Fred Hebert’s “Zippers” library, under the MIT licence.

Summary

Types

t()

A Zipper binary tree

Functions

Adds a left child to the tree

Returns the current element in the binary tree in a tuple

Checks if a node is a leaf, that is to say if it has no child

Goes down the tree, with the current element being the left child, or returns nil if there is no child

Replaces the current element in the tree (if it exists) or create a new node (if it doesn’t)

Goes down the tree, with the current element being the right child

Create a new basic binary tree. It should be declared first when declaring the data structure

Goes up the tree, or returns nil if we’re already at the top of the tree

Types

t()
t() :: {thread(any), node(any)}

A Zipper binary tree

Functions

add_left(new_branch, zipper)
add_left(Zippy.ZBinTree.t, term) :: Zippy.ZBinTree.t

Adds a left child to the tree

add_right(new_branch, zipper)
add_right(Zippy.ZBinTree.t, term) :: Zippy.ZBinTree.t
current(arg)
current(ZBintTree.t) :: {:ok, term} | {:error, nil}

Returns the current element in the binary tree in a tuple.

leaf?(arg)
leaf?(Zippy.ZBinTree.t) :: boolean

Checks if a node is a leaf, that is to say if it has no child.

left(arg)

Goes down the tree, with the current element being the left child, or returns nil if there is no child

replace(value, arg)

Replaces the current element in the tree (if it exists) or create a new node (if it doesn’t).

right(arg)

Goes down the tree, with the current element being the right child.

root(a)
root(term) :: Zippy.ZBinTree.t

Create a new basic binary tree. It should be declared first when declaring the data structure.

up(arg)
up(Zippy.ZBinTree.t) :: Zippy.ZBinTree | nil

Goes up the tree, or returns nil if we’re already at the top of the tree.