CCRAL
Random-Access Lists
This is an OCaml implementation of Okasaki's paper "Purely Functional Random Access Lists". It defines a list-like data structure with O(1) cons/tail operations, and O(log(n)) lookup/modification operations.
This module used to be part of containers.misc
status: stable
val empty : 'a t
Empty list.
val is_empty : _ t -> bool
Check whether the list is empty.
val return : 'a -> 'a t
Singleton.
val hd : 'a t -> 'a
First element of the list, or
val length : 'a t -> int
Number of elements. Complexity O(ln n)
where n=number of elements.
val get : 'a t -> int -> 'a option
get l i
accesses the i
-th element of the list. O(log(n))
.
get_and_remove_exn l i
accesses and removes the i
-th element of l
.
take_drop n l
splits l
into a, b
such that length a = n
if length l >= n
, and such that append a b = l
.
val iter : f:('a -> unit) -> 'a t -> unit
Iterate on the list's elements.
val iteri : f:(int -> 'a -> unit) -> 'a t -> unit
val fold : f:('b -> 'a -> 'b) -> x:'b -> 'a t -> 'b
Fold on the list's elements.
val fold_rev : f:('b -> 'a -> 'b) -> x:'b -> 'a t -> 'b
Fold on the list's elements, in reverse order (starting from the tail).
val make : int -> 'a -> 'a t
val range : int -> int -> int t
range i j
is i; i+1; ... ; j
or j; j-1; ...; i
.
val of_list : 'a list -> 'a t
Convert a list to a RAL. Caution: non tail-rec.
val to_list : 'a t -> 'a list
val of_array : 'a array -> 'a t
val to_array : 'a t -> 'a array
More efficient than on usual lists.
module Infix : sig ... end