Module CCVector

Growable, mutable vector

type ro = [
| `RO
]
type rw = [
| `RW
]

Mutability is rw (read-write) or ro (read-only).

type ('a, 'mut) t

The type of a vector of elements of type 'a, with a mutability flat 'mut.

type 'a vector = ('arwt

Type synonym: a 'a vector is mutable.

type 'a ro_vector = ('arot

Alias for immutable vectors.

type 'a sequence = ('a ‑> unit) ‑> unit
type 'a klist = unit ‑> [ `Nil | `Cons of 'a * 'a klist ]
type 'a gen = unit ‑> 'a option
type 'a equal = 'a ‑> 'a ‑> bool
type 'a ord = 'a ‑> 'a ‑> int
type 'a printer = Format.formatter ‑> 'a ‑> unit
val freeze : ('a_t ‑> ('arot

Make an immutable vector (no copy! Don't use the old version).

val freeze_copy : ('a_t ‑> ('arot

Copy the vector into an immutable version.

val create : unit ‑> ('arwt

Create a new, empty vector.

val create_with : ?⁠capacity:int ‑> 'a ‑> ('arwt

Create a new vector, using the given value as a filler.

val return : 'a ‑> ('a'mutt

Singleton vector.

val make : int ‑> 'a ‑> ('a'mutt

make n x makes a vector of size n, filled with x.

val init : int ‑> (int ‑> 'a) ‑> ('a'mutt

Init the vector with the given function and size.

val clear : ('arwt ‑> unit

Clear the content of the vector.

val ensure_with : init:'a ‑> ('arwt ‑> int ‑> unit

Hint to the vector that it should have at least the given capacity.

val ensure : ('arwt ‑> int ‑> unit

Hint to the vector that it should have at least the given capacity. Just a hint, will not be enforced if the vector is empty and init is not provided.

val is_empty : ('a_t ‑> bool

Is the vector empty?

val push : ('arwt ‑> 'a ‑> unit

Add an element at the end of the vector.

val append : ('arwt ‑> ('a_t ‑> unit

append a b adds all elements of b to a.

val append_array : ('arwt ‑> 'a array ‑> unit

Like append, with an array.

val append_seq : ('arwt ‑> 'a sequence ‑> unit

Append content of sequence.

val append_list : ('arwt ‑> 'a list ‑> unit

Append content of list.

val append_gen : ('arwt ‑> 'a gen ‑> unit

Append content of generator.

val equal : 'a equal ‑> ('a_t equal
val compare : 'a ord ‑> ('a_t ord

Total ordering on vectors. Lexicographic comparison.

exception Empty

Raised on empty stack.

val pop : ('arwt ‑> 'a option

Remove last element, or None.

val pop_exn : ('arwt ‑> 'a

Remove last element, or raise a Failure if empty.

val top : ('a_t ‑> 'a option

Top element, if present.

val top_exn : ('a_t ‑> 'a

Top element, if present.

val copy : ('a_t ‑> ('a'mutt

Shallow copy (may give an immutable or mutable vector).

val shrink : ('arwt ‑> int ‑> unit

Shrink to the given size (remove elements above this size). Does nothing if the parameter is bigger than the current size.

val member : eq:('a ‑> 'a ‑> bool) ‑> 'a ‑> ('a_t ‑> bool

Is the element a member of the vector?

val sort : ('a ‑> 'a ‑> int) ‑> ('a_t ‑> ('a'mutt

Sort the vector, returning a copy of it that is sorted w.r.t the given ordering. The vector itself is unchanged.

val sort' : ('a ‑> 'a ‑> int) ‑> ('arwt ‑> unit

Sort the vector in place (modifying it).

val uniq_sort : ('a ‑> 'a ‑> int) ‑> ('arwt ‑> unit

Sort the array and remove duplicates, in place (e.g. modifying the vector itself).

val iter : ('a ‑> unit) ‑> ('a_t ‑> unit

Iterate on the vector's content.

val iteri : (int ‑> 'a ‑> unit) ‑> ('a_t ‑> unit

Iterate on the vector, with indexes.

val map : ('a ‑> 'b) ‑> ('a_t ‑> ('b'mutt

Map elements of the vector, yielding a new vector.

val filter : ('a ‑> bool) ‑> ('a_t ‑> ('a'mutt

Filter elements from the vector. filter p v leaves v unchanged but returns a new vector that only contains elements of v satisfying p.

val filter' : ('a ‑> bool) ‑> ('arwt ‑> unit

Filter elements in place.

val fold : ('b ‑> 'a ‑> 'b) ‑> 'b ‑> ('a_t ‑> 'b

Fold on elements of the vector

val exists : ('a ‑> bool) ‑> ('a_t ‑> bool

Existential test (is there an element that satisfies the predicate?).

val for_all : ('a ‑> bool) ‑> ('a_t ‑> bool

Universal test (do all the elements satisfy the predicate?).

val find : ('a ‑> bool) ‑> ('a_t ‑> 'a option

Find an element that satisfies the predicate.

val find_exn : ('a ‑> bool) ‑> ('a_t ‑> 'a

Find an element that satisfies the predicate, or

val find_map : ('a ‑> 'b option) ‑> ('a_t ‑> 'b option

find_map f v returns the first Some y = f x for x in v, or None if f x = None for each x in v.

val filter_map : ('a ‑> 'b option) ‑> ('a_t ‑> ('b'mutt

Map elements with a function, possibly filtering some of them out.

val flat_map : ('a ‑> ('b_t) ‑> ('a_t ‑> ('b'mutt

Map each element to a sub-vector.

val flat_map_seq : ('a ‑> 'b sequence) ‑> ('a_t ‑> ('b'mutt

Like flat_map, but using sequence for intermediate collections.

val flat_map_list : ('a ‑> 'b list) ‑> ('a_t ‑> ('b'mutt

Like flat_map, but using list for intermediate collections.

val (>>=) : ('a_t ‑> ('a ‑> ('b_t) ‑> ('b'mutt

Infix version of flat_map.

val (>|=) : ('a_t ‑> ('a ‑> 'b) ‑> ('b'mutt

Infix version of map.

val get : ('a_t ‑> int ‑> 'a

Access element by its index, or

val set : ('arwt ‑> int ‑> 'a ‑> unit

Modify element at given index, or

val remove : ('arwt ‑> int ‑> unit

Remove the n-th element of the vector. Does NOT preserve the order of the elements (might swap with the last element).

val rev : ('a_t ‑> ('a'mutt

Reverse the vector.

val rev_in_place : ('arwt ‑> unit

Reverse the vector in place.

val rev_iter : ('a ‑> unit) ‑> ('a_t ‑> unit

rev_iter f a is the same as iter f (rev a), only more efficient.

val size : ('a_t ‑> int

Number of elements in the vector.

val length : (__t ‑> int

Synonym for size.

val capacity : (__t ‑> int

Number of elements the vector can contain without being resized.

val unsafe_get_array : ('arwt ‑> 'a array

Access the underlying shared array (do not modify!). unsafe_get_array v is longer than size v, but elements at higher index than size v are undefined (do not access!).

val (--) : int ‑> int ‑> (int, 'mutt

Range of integers, either ascending or descending (both included, therefore the result is never empty). Example: 1 -- 10 returns the vector [1;2;3;4;5;6;7;8;9;10].

val (--^) : int ‑> int ‑> (int, 'mutt

Range of integers, either ascending or descending, but excluding right. Example: 1 --^ 10 returns the vector [1;2;3;4;5;6;7;8;9].

val of_array : 'a array ‑> ('a'mutt

of_array a returns a vector corresponding to the array a. Operates in O(n) time.

val of_list : 'a list ‑> ('a'mutt
val to_array : ('a_t ‑> 'a array

to_array v returns an array corresponding to the vector v.

val to_list : ('a_t ‑> 'a list

Return a list with the elements contained in the vector.

val of_seq : ?⁠init:('arwt ‑> 'a sequence ‑> ('arwt
val to_seq : ('a_t ‑> 'a sequence

Return a sequence with the elements contained in the vector.

val to_seq_rev : ('a_t ‑> 'a sequence

to_seq_rev v returns the sequence of elements of v in reverse order, that is, the last elements of v are iterated on first.

val slice : ('arwt ‑> 'a array * int * int

Vector as an array slice. By doing it we expose the internal array, so be careful!.

val slice_seq : ('a_t ‑> int ‑> int ‑> 'a sequence

slice_seq v start len is the sequence of elements from v.(start) to v.(start+len-1).

val of_klist : ?⁠init:('arwt ‑> 'a klist ‑> ('arwt
val to_klist : ('a_t ‑> 'a klist
val of_gen : ?⁠init:('arwt ‑> 'a gen ‑> ('arwt
val to_gen : ('a_t ‑> 'a gen
val pp : ?⁠start:string ‑> ?⁠stop:string ‑> ?⁠sep:string ‑> 'a printer ‑> ('a_t printer