package core_kernel
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=e37370bad978cfb71fdaf2b1a25ab1506b98ef0b91e0dbd189ffd9d853245ce2
doc/core_kernel.vec/Vec/index.html
Module Vec
Source
A growable array of 'a
. Designed for efficiency and simplicity.
This interface is generated lazily: if you need a standard function we haven't added, feel free to add or ping the authors.
By default, Vec
operations use integers as indices. The functor Make
can be used to create a specialized version from any module implementing Intable.S
.
init n ~f
returns a fresh vector of length n
, with element number i
initialized to the result of f i
. In other words, init n ~f
tabulates the results of f
applied to the integers 0
to n-1
.
Raise Invalid_argument if n < 0
.
sort
uses constant heap space. To sort only part of the array, specify pos
to be the index to start sorting from and len
indicating how many elements to sort.
Grows the vec to the specified length if it is currently shorter. Sets all new indices to default
.
Shortens the vec to the specified length if it is currently longer. Raises if len < 0
.
remove vec i
Removes the i-th element of the vector. This is not a fast implementation, and runs in O(N) time. (ie: it calls caml_modify under the hood)
Find the first element that satisfies f
. If exists, remove the element from the vector and return it. This is not a fast implementation, and runs in O(N) time.
take_while t ~f
returns a fresh vec containing the longest prefix of t
for which f
is true
.
copy t
returns a copy of t
, that is, a fresh vec containing the same elements as t
.
exists t ~f
returns true if f
evaluates true on any element, else false
swap_to_last_and_pop t i
is equivalent to swap t i (length t - 1); pop_back_exn t
. It raises if i
is out of bounds.