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
List containing elements of type 'a
val is_empty : _ t -> boolCheck whether the list is empty.
val cons : 'a -> 'a t -> 'a tAdd an element at the front of the list.
val map : f:('a -> 'b) -> 'a t -> 'b tval mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b tFirst element of the list, or
Remove the first element from the list, or
val front : 'a t -> ('a * 'a t) optionRemove and return the first element of the list.
val front_exn : 'a t -> 'a * 'a tNumber of elements. Complexity O(ln n) where n=number of elements.
val get : 'a t -> int -> 'a optionget l i accesses the i-th element of the list. O(log(n)).
val get_exn : 'a t -> int -> 'aval set : 'a t -> int -> 'a -> 'a tset l i v sets the i-th element of the list to v. O(log(n)).
val remove : 'a t -> int -> 'a tremove l i removes the i-th element of l.
val get_and_remove_exn : 'a t -> int -> 'a * 'a tget_and_remove_exn l i accesses and removes the i-th element of l.
val append : 'a t -> 'a t -> 'a tval filter : f:('a -> bool) -> 'a t -> 'a tval filter_map : f:('a -> 'b option) -> 'a t -> 'b tval flat_map : ('a -> 'b t) -> 'a t -> 'b tval flatten : 'a t t -> 'a tval app : ('a -> 'b) t -> 'a t -> 'b tval take : int -> 'a t -> 'a tval take_while : f:('a -> bool) -> 'a t -> 'a tval drop : int -> 'a t -> 'a tval drop_while : f:('a -> bool) -> 'a t -> 'a tval take_drop : int -> 'a t -> 'a t * 'a ttake_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 -> unitIterate on the list's elements.
val iteri : f:(int -> 'a -> unit) -> 'a t -> unitval fold : f:('b -> 'a -> 'b) -> x:'b -> 'a t -> 'bFold on the list's elements.
val fold_rev : f:('b -> 'a -> 'b) -> x:'b -> 'a t -> 'bFold on the list's elements, in reverse order (starting from the tail).
val rev_map : f:('a -> 'b) -> 'a t -> 'b trev_map f l is the same as map f (rev l).
val equal : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> boolval compare : cmp:('a -> 'a -> int) -> 'a t -> 'a t -> intLexicographic comparison.
Utils
val make : int -> 'a -> 'a tval repeat : int -> 'a t -> 'a trepeat n l is append l (append l ... l) n times.
val range : int -> int -> int trange i j is i; i+1; ... ; j or j; j-1; ...; i.
Conversions
type 'a iter = ('a -> unit) -> unittype 'a gen = unit -> 'a optionval add_list : 'a t -> 'a list -> 'a tval of_list : 'a list -> 'a tConvert a list to a RAL. Caution: non tail-rec.
val to_list : 'a t -> 'a listval of_list_map : f:('a -> 'b) -> 'a list -> 'b tval of_array : 'a array -> 'a tval add_array : 'a t -> 'a array -> 'a tval to_array : 'a t -> 'a arrayMore efficient than on usual lists.
val add_iter : 'a t -> 'a iter -> 'a tval of_iter : 'a iter -> 'a tval to_iter : 'a t -> 'a iterval add_gen : 'a t -> 'a gen -> 'a tval of_gen : 'a gen -> 'a tval to_gen : 'a t -> 'a genInfix
module Infix : sig ... endinclude module type of Infix
val (@+) : 'a -> 'a t -> 'a tval (>>=) : 'a t -> ('a -> 'b t) -> 'b tval (>|=) : 'a t -> ('a -> 'b) -> 'b tval (<*>) : ('a -> 'b) t -> 'a t -> 'b tval (--) : int -> int -> int tval (--^) : int -> int -> int ta --^ b is the integer range from a to b, where b is excluded.
IO
type 'a printer = Stdlib.Format.formatter -> 'a -> unit