package knights_tour

  1. Overview
  2. Docs

A Treequence is 'pure/functional' data structure that represents a finite, ordered sequence of elements. I.e it is much like a list. Unlike a typical list implementation it supports efficient pushing and popping on both the front and back. Thus it can be used interchangeably as a Stack or a Queue without much of a performance penalty.

type 'a t

A 'a t is a Treequence containing elements of type 'a.

val empty : 'a t

An empty Treequence, contains no elements.

val is_empty : 'a t -> bool

is_empty t is true iff there are no elements in t.

val map : ('a -> 'b) -> 'a t -> 'b t

map f t applies a function to each element of t, creating a new Treequence with the results.

val singleton : 'a -> 'a t

Creates a Treequence containing a single element.

val size : 'a t -> int

size t returns the number of elements in t. This operation is O(1).

val push : 'a -> 'a t -> 'a t

push el t Adds an element to the front of t.

val pop : 'a t -> ('a * 'a t) option

pop el t Removes an element from the front of t.

val push_end : 'a -> 'a t -> 'a t

push_end el t Adds an element to the end of t.

val pop_end : 'a t -> ('a * 'a t) option

pop_end el t Removes an element from the end of t.

val append : 'a t -> 'a t -> 'a t

append s1 s2 Creates Treequence that contains all elements of s1 followed by all elements of s2.

val to_string : ('a -> string) -> 'a t -> string

Converts Treequence into a string revealing its internal structure. Useful for debugging and testing.

OCaml

Innovation. Community. Security.