package containers

  1. Overview
  2. Docs
A modular, clean and powerful extension of the OCaml standard library

Install

Dune Dependency

Authors

Maintainers

Sources

v2.8.1.tar.gz
md5=d84e09c5d0abc501aa17cd502e31a038
sha512=8b832f4ada6035e80d81be0cfb7bdffb695ec67d465ed6097a144019e2b8a8f909095e78019c3da2d8181cc3cd730cd48f7519e87d3162442562103b7f36aabb

doc/containers/CCVector/index.html

Module CCVectorSource

Growable, mutable vector

Sourcetype ro = [
  1. | `RO
]
Sourcetype rw = [
  1. | `RW
]

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

Sourcetype ('a, 'mut) t

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

Sourcetype 'a vector = ('a, rw) t

Type synonym: a 'a vector is mutable.

Sourcetype 'a ro_vector = ('a, ro) t

Alias for immutable vectors.

  • since 0.15
Sourcetype 'a sequence = ('a -> unit) -> unit
  • deprecated

    use 'a iter instead

Sourcetype 'a iter = ('a -> unit) -> unit

Fast internal iterator.

  • since 2.8
Sourcetype 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
Sourcetype 'a gen = unit -> 'a option
Sourcetype 'a equal = 'a -> 'a -> bool
Sourcetype 'a ord = 'a -> 'a -> int
Sourcetype 'a printer = Format.formatter -> 'a -> unit
Sourceval freeze : ('a, _) t -> ('a, ro) t

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

Sourceval freeze_copy : ('a, _) t -> ('a, ro) t

Copy the vector into an immutable version.

Sourceval create : unit -> ('a, rw) t

Create a new, empty vector.

Sourceval create_with : ?capacity:int -> 'a -> ('a, rw) t

Create a new vector, the value is used to enforce the type the new vector.

  • parameter capacity

    the size of the underlying array.

Sourceval return : 'a -> ('a, 'mut) t

Singleton vector.

  • since 0.14
Sourceval make : int -> 'a -> ('a, 'mut) t

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

Sourceval init : int -> (int -> 'a) -> ('a, 'mut) t

Init the vector with the given function and size.

Sourceval clear : ('a, rw) t -> unit

Clear the content of the vector.

Sourceval clear_and_reset : ('a, rw) t -> unit

Clear the content of the vector, and deallocate the underlying array, removing references to all the elements.

  • since 2.8
Sourceval ensure_with : init:'a -> ('a, rw) t -> int -> unit

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

  • parameter init

    if capacity v = 0, used to enforce the type of the vector (see create_with).

  • since 0.14
Sourceval ensure : ('a, rw) t -> 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.

Sourceval is_empty : ('a, _) t -> bool

Is the vector empty?

Sourceval push : ('a, rw) t -> 'a -> unit

Add an element at the end of the vector.

Sourceval append : ('a, rw) t -> ('a, _) t -> unit

append a b adds all elements of b to a.

Sourceval append_array : ('a, rw) t -> 'a array -> unit

Like append, with an array.

Sourceval append_iter : ('a, rw) t -> 'a iter -> unit

Append content of iterator.

  • since 2.8
Sourceval append_std_seq : ('a, rw) t -> 'a Seq.t -> unit

Append content of iterator.

  • since 2.8
Sourceval append_seq : ('a, rw) t -> 'a sequence -> unit

Append content of sequence.

Sourceval append_list : ('a, rw) t -> 'a list -> unit

Append content of list.

  • since 0.14
Sourceval append_gen : ('a, rw) t -> 'a gen -> unit

Append content of generator.

  • since 0.20
Sourceval equal : 'a equal -> ('a, _) t equal
Sourceval compare : 'a ord -> ('a, _) t ord

Total ordering on vectors. Lexicographic comparison.

Sourceexception Empty

Raised on empty stack.

Sourceval pop : ('a, rw) t -> 'a option

Remove last element, or None.

Sourceval pop_exn : ('a, rw) t -> 'a

Remove last element, or raise a Failure if empty.

  • raises Empty

    on an empty vector.

Sourceval top : ('a, _) t -> 'a option

Top element, if present.

  • since 0.6
Sourceval top_exn : ('a, _) t -> 'a

Top element, if present.

  • raises Empty

    on an empty vector.

  • since 0.6
Sourceval copy : ('a, _) t -> ('a, 'mut) t

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

Sourceval shrink : ('a, rw) t -> int -> unit

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

Sourceval shrink_to_fit : ('a, _) t -> unit

Shrink internal array to fit the size of the vector

  • since 2.8
Sourceval member : eq:('a -> 'a -> bool) -> 'a -> ('a, _) t -> bool

Is the element a member of the vector?

Sourceval sort : ('a -> 'a -> int) -> ('a, _) t -> ('a, 'mut) t

Sort the vector, returning a copy of it that is sorted w.r.t the given ordering. The vector itself is unchanged. The underlying array of the new vector can be smaller than the original one.

Sourceval sort' : ('a -> 'a -> int) -> ('a, rw) t -> unit

Sort the vector in place (modifying it). This function change the size of the underlying array.

Sourceval uniq_sort : ('a -> 'a -> int) -> ('a, rw) t -> unit

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

Sourceval iter : ('a -> unit) -> ('a, _) t -> unit

Iterate on the vector's content.

Sourceval iteri : (int -> 'a -> unit) -> ('a, _) t -> unit

Iterate on the vector, with indexes.

Sourceval map : ('a -> 'b) -> ('a, _) t -> ('b, 'mut) t

Map elements of the vector, yielding a new vector.

Sourceval mapi : (int -> 'a -> 'b) -> ('a, _) t -> ('b, 'mut) t

map f v is just like map, but it also passes in the index of each element as the first argument to the function f.

  • since 2.8
Sourceval map_in_place : ('a -> 'a) -> ('a, _) t -> unit

Map elements of the vector in place

  • since 2.3
Sourceval filter : ('a -> bool) -> ('a, _) t -> ('a, 'mut) t

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

Sourceval filter' : ('a -> bool) -> ('a, rw) t -> unit

Filter elements in place.

Sourceval fold : ('b -> 'a -> 'b) -> 'b -> ('a, _) t -> 'b

Fold on elements of the vector

Sourceval exists : ('a -> bool) -> ('a, _) t -> bool

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

Sourceval for_all : ('a -> bool) -> ('a, _) t -> bool

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

Sourceval find : ('a -> bool) -> ('a, _) t -> 'a option

Find an element that satisfies the predicate.

Sourceval find_exn : ('a -> bool) -> ('a, _) t -> 'a

Find an element that satisfies the predicate, or

Sourceval 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.

  • since 0.14
Sourceval filter_map : ('a -> 'b option) -> ('a, _) t -> ('b, 'mut) t

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

Sourceval filter_map_in_place : ('a -> 'a option) -> ('a, _) t -> unit

Filter-map elements of the vector in place

  • since 2.3
Sourceval flat_map : ('a -> ('b, _) t) -> ('a, _) t -> ('b, 'mut) t

Map each element to a sub-vector.

Sourceval flat_map_iter : ('a -> 'b sequence) -> ('a, _) t -> ('b, 'mut) t

Like flat_map, but using iter for intermediate collections.

  • since 2.8
Sourceval flat_map_std_seq : ('a -> 'b Seq.t) -> ('a, _) t -> ('b, 'mut) t

Like flat_map, but using Seq for intermediate collections.

  • since 2.8
Sourceval flat_map_seq : ('a -> 'b sequence) -> ('a, _) t -> ('b, 'mut) t
  • deprecated use flat_map_iter or flat_map_std_seq
Sourceval flat_map_list : ('a -> 'b list) -> ('a, _) t -> ('b, 'mut) t

Like flat_map, but using list for intermediate collections.

  • since 0.14
Sourceval monoid_product : ('a -> 'b -> 'c) -> ('a, _) t -> ('b, _) t -> ('c, _) t

All combinaisons of tuples from the two vectors are passed to the function.

  • since 2.8
Sourceval (>>=) : ('a, _) t -> ('a -> ('b, _) t) -> ('b, 'mut) t

Infix version of flat_map.

Sourceval (>|=) : ('a, _) t -> ('a -> 'b) -> ('b, 'mut) t

Infix version of map.

Sourceval get : ('a, _) t -> int -> 'a

Access element by its index, or

Sourceval set : ('a, rw) t -> int -> 'a -> unit

Modify element at given index, or

Sourceval remove : ('a, rw) t -> int -> unit

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

Sourceval rev : ('a, _) t -> ('a, 'mut) t

Reverse the vector.

Sourceval rev_in_place : ('a, rw) t -> unit

Reverse the vector in place.

  • since 0.14
Sourceval rev_iter : ('a -> unit) -> ('a, _) t -> unit

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

  • since 0.14
Sourceval size : ('a, _) t -> int

Number of elements in the vector.

Sourceval length : (_, _) t -> int

Synonym for size.

Sourceval capacity : (_, _) t -> int

Number of elements the vector can contain without being resized.

Sourceval unsafe_get_array : ('a, rw) t -> '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!).

Sourceval (--) : int -> int -> (int, 'mut) t

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].

Sourceval (--^) : int -> int -> (int, 'mut) t

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].

  • since 0.17
Sourceval of_array : 'a array -> ('a, 'mut) t

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

Sourceval of_list : 'a list -> ('a, 'mut) t
Sourceval to_array : ('a, _) t -> 'a array

to_array v returns an array corresponding to the vector v.

Sourceval to_list : ('a, _) t -> 'a list

Return a list with the elements contained in the vector.

Sourceval of_iter : ?init:('a, rw) t -> 'a iter -> ('a, rw) t

Convert an Iterator to a vector.

  • since 2.8.1
Sourceval of_seq : ?init:('a, rw) t -> 'a sequence -> ('a, rw) t
  • deprecated use of_iter. For the standard Seq, see {!of_std_seq}
Sourceval of_std_seq : ?init:('a, rw) t -> 'a Seq.t -> ('a, rw) t
  • deprecated use of_iter. For the standard Seq, see {!of_std_seq}
Sourceval to_iter : ('a, _) t -> 'a iter

Return a iter with the elements contained in the vector.

  • since 2.8
Sourceval to_iter_rev : ('a, _) t -> 'a iter

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

  • since 2.8
Sourceval to_std_seq : ('a, _) t -> 'a Seq.t

Return an iterator with the elements contained in the vector.

  • since 2.8
Sourceval to_std_seq_rev : ('a, _) t -> 'a Seq.t

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

  • since 2.8
Sourceval to_seq : ('a, _) t -> 'a sequence
  • deprecated use to_iter. For the standard Seq, see {!to_std_seq}
Sourceval to_seq_rev : ('a, _) t -> 'a sequence
  • deprecated use to_iter_rev. For the standard Seq, see {!to_std_seq_rev}
Sourceval slice : ('a, rw) t -> 'a array * int * int

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

Sourceval 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).

Sourceval fill_empty_slots_with : ('a, _) t -> 'a -> unit
  • deprecated not needed anymore, see #279,#282,#283
Sourceval of_klist : ?init:('a, rw) t -> 'a klist -> ('a, rw) t
Sourceval to_klist : ('a, _) t -> 'a klist
Sourceval of_gen : ?init:('a, rw) t -> 'a gen -> ('a, rw) t
Sourceval to_gen : ('a, _) t -> 'a gen
Sourceval to_string : ?start:string -> ?stop:string -> ?sep:string -> ('a -> string) -> ('a, _) t -> string

Print the vector in a string

  • since 2.7
Sourceval pp : ?start:string -> ?stop:string -> ?sep:string -> 'a printer -> ('a, _) t printer

Let operators on OCaml >= 4.08.0, nothing otherwise

  • since 2.8
include CCShimsMkLet_.S2 with type ('a, 'e) t_let2 := ('a, 'e) t
Sourceval (let+) : ('a, 'e) t -> ('a -> 'b) -> ('b, 'e) t
Sourceval (and+) : ('a, 'e) t -> ('b, 'e) t -> ('a * 'b, 'e) t
Sourceval (let*) : ('a, 'e) t -> ('a -> ('b, 'e) t) -> ('b, 'e) t
Sourceval (and*) : ('a, 'e) t -> ('b, 'e) t -> ('a * 'b, 'e) t
OCaml

Innovation. Community. Security.