rose_tree

A rose tree is a recursive n-ary tree. rose_tree implements the data structure and provides raw and zipper-based traversal and manipulation.


License
BSD-3-Clause-Attribution

Documentation

RoseTree

https://circleci.com/gh/tpoulsen/rose_tree.svg?style=svg https://img.shields.io/hexpm/v/rose_tree.svg

An n-ary tree by any other name…

A rose tree is an n-ary tree in which each node has zero or more children, all of which are themselves rose trees.

Ex: img/rose_tree_diagram.png

Up-to-date documentation can be found on hex.

Functions

RoseTree

Tree creation

  • RoseTree.new/0
  • RoseTree.new/1
  • RoseTree.new/2
  • RoseTree.from_map/1

Node insertion/removal/validation

  • RoseTree.add_child/2
  • RoseTree.add_child/2
  • RoseTree.pop_child/1
  • RoseTree.pop_child_at/2
  • RoseTree.elem_at/2

Node manipulation

  • RoseTree.map/2
  • RoseTree.update_node/3
  • RoseTree.update_children/3
  • RoseTree.merge_nodes/2

Traversal

  • RoseTree.to_list/1
  • RoseTree.paths/1
  • RoseTree.child_values/1

Predicates

  • RoseTree.is_child?/2

RoseTree.Zipper

Creation/Extraction

  • RoseTree.Zipper.to_tree/1
  • RoseTree.Zipper.from_tree/1

Traversal

  • RoseTree.Zipper.nth_child/2
  • RoseTree.Zipper.ascend/1
  • RoseTree.Zipper.to_root/1
  • RoseTree.Zipper.next_sibling/1
  • RoseTree.Zipper.previous_sibling/1
  • RoseTree.Zipper.last_child/1
  • RoseTree.Zipper.first_child/1
  • RoseTree.Zipper.find_child/2

Modification

  • RoseTree.Zipper.prune/1
  • RoseTree.Zipper.modify/2
  • RoseTree.Zipper.lift/2
  • RoseTree.Zipper.insert_left/2
  • RoseTree.Zipper.insert_right/2
  • RoseTree.Zipper.insert_first_child/2
  • RoseTree.Zipper.insert_last_child/2
  • RoseTree.Zipper.insert_nth_child/3

Predicates

  • RoseTree.Zipper.root?/1
  • RoseTree.Zipper.leaf?/1
  • RoseTree.Zipper.first?/1
  • RoseTree.Zipper.last?/1
  • RoseTree.Zipper.only_child?/1
  • RoseTree.Zipper.has_parent?/1
  • RoseTree.Zipper.has_children?/1

Protocols

RoseTree implements the Enumerable protocol, so all applicable Enum and Stream functions are usable with a RoseTree.

Installation

Add rose_tree to your list of dependencies in mix.exs:

def deps do
  [{:rose_tree, "~> 0.2.0"}]
end