package patoline

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Functor to build tree and zipper data structurs with data on the nodes and on the leaves.

Parameters

module D : TreeData

Signature

type tree = D.tree

Type of a tree.

type node = D.node

Type of internal nodes in the tree.

type zipper = tree * (int * node) list

Type of a zipper.

val tree_to_zipper : tree -> zipper

Convert a tree into a zipper pointing at its root.

val zipper_to_tree : zipper -> tree

Obtain the tree represented by the given zipper.

val empty : node -> zipper

Build an empty zipper consisting of a single node with no child.

val is_root : zipper -> bool

Return true if the zipper points at the root of the tree.

val up : zipper -> zipper

Go up one level in the zipper. Raises Invalid_argument if the zipper points at the root of the tree.

val up_n : int -> zipper -> zipper

Applies up the given number of times. Raises Invalid_argument if the zipper reaches the root of the tree too soon.

val top : zipper -> zipper

Move the zipper to the root of the tree.

val down : zipper -> int -> zipper

Move down the i-th branch of the pointed tree. This function raises Invalid_argument if no such branch exist, or if the pointed tree is not a node.

val down_path : zipper -> int list -> zipper

Move down branches along the given path. Raises Invalid_argument if the path is not valid.

val min_index : zipper -> int

Return the minimum child index for the pointed tree. Raises Invalid_argument if the pointed tree is not a node.

val max_index : zipper -> int

Return the maximum child index for the pointed tree. Raises Invalid_argument if the pointed tree is not a node.

val down_first : zipper -> zipper

Move down the child with the lowest index. The function raises Invalid_argument if the pointed tree is not a node or if it does not have any child.

val down_last : zipper -> zipper

Same as down_first with the last child.

val new_child : zipper -> tree -> int -> zipper

Add a new child under the pointed node, at the given index. If the pointed tree is not a node, or if there is already a child at the given index, the exception Invalid_argument is raised. The returned zipper points to the new child.

val new_last_child : zipper -> tree -> zipper

Add a new child with the highest indext under the current node. The exception Invalid_argument is raised if the pointed tree is not a node. The returned zipper points to the new child.

val new_first_child : zipper -> tree -> zipper

Same as new_last_child but the inserted child will have the lowest index under the node.

val has_child : zipper -> int -> bool

Return true if the pointed node has a child at the given index. The exception Invalid_argument is raised if the pointed tree is not a node.

val remove_child : zipper -> int -> zipper

Remove the child at the given index in the node pointed to by the zipper. If the zipper does not point to a node, or if the child does not exist, the exception Invalid_argument is raised.

OCaml

Innovation. Community. Security.