package grenier

  1. Overview
  2. Docs
A collection of various algorithms in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

grenier-0.15.tbz
sha256=dec7f84b9e93d5825f10c7dea84d5a74d7365ede45664ae63c26b5e8045c1c44
sha512=b8aa1569c2e24b89674d1b34de34cd1798896bb6a53aa5a1287f68cee880125e6b687f66ad73da9069a01cc3ece1f0684f48328b099d43529bff736b772c8fd8

doc/grenier.dbseq/Dbseq/index.html

Module DbseqSource

Dbseq immutable sequence

Dbseq is a small data structure that offers operations halfway between a list and an immutable array. Most operations have a logarithmic cost. In practice, it is a log with base 4 and small constant factors.

This data structure is particularly suitable to associate metadata to variables in De-Bruijn notation (hence the name).

Sourcetype +'a t

Sequences with element of type 'a *

Sourceval empty : 'a t

The empty sequence

Sourceval cons : 'a -> 'a t -> 'a t

cons x xs adds element x at the beginning of sequence xs. x now has index 0 and xs's elements are shifted by 1. Worst-case cost is O(log n), though the amortized cost is O(1).

Sourceval get : int -> 'a t -> 'a

get i xs access the i'th element of xs in cost O(log i). In particular, access to recent elements is quasi constant.

The operation is only defined if 0 <= i < length xs, and will raise Not_found if i is out of bounds.

O(log i).

Sourceval set : int -> 'a -> 'a t -> 'a t

set i x xs update the i'th element of xs to value x in cost O(log i).

The operation is only defined if 0 <= i < length xs, and will raise Not_found if i is out of bounds.

O(log i).

Sourceval update : 'a t -> int -> ('a -> 'a) -> 'a t

update xs i f behaves like set i (f (get i xs)) xs.

O(log i).

Sourceval length : 'a t -> int

n = length xs is the number of elements in xs.

O(log n).

Sourceval is_empty : 'a t -> bool

is_empty t iff t = empty (equivalently length t = 0).

O(1).

Sourceval uncons : 'a t -> ('a * 'a t) option

Revert the effect of the last cons (with the same complexity).

Sourceval drop : int -> 'a t -> 'a t

drop n x removes n elements from x. Faster than uncons'ing n times. (TODO: determine complexity)

Sourceval to_seq : 'a t -> 'a Seq.t

Returns the sequence of elements, in order (get 0, get 1, ...). O(1) per element on average, O(log n) per element worst case.

Sourceval to_rev_seq : 'a t -> 'a Seq.t

Returns the sequence of elements, in reverse order (get (length - 1), get (length - 2), ...). O(1) per element on average, O(log n) per element worst case.

OCaml

Innovation. Community. Security.