package containers
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=c94fba0c7c54349b7021c31f85120495197ddde438c574d48362ec669bf7e564
sha512=b33588d9df66a858083616cc70cd82822cecc2dcec8902759e72648e5c41c887556da0a28317f388d34afe319309c20dd8baa7508d003dddff00e83869fad861
doc/containers/CCVector/index.html
Module CCVector
Source
Growable, mutable vector
Mutability is rw
(read-write) or ro
(read-only).
The type of a vector of elements of type 'a
, with a mutability flat 'mut
.
Fast internal iterator.
Make an immutable vector (no copy! Don't use the old version).
Create a new vector, the value is used to enforce the type the new vector.
Init the vector with the given function and size.
Clear the content of the vector. This ensures that length v = 0
but the underlying array is kept, and possibly references to former elements, which are therefore not garbage collectible.
Clear the content of the vector, and deallocate the underlying array, removing references to all the elements. The elements can be collected.
Hint to the vector that it should have at least the given capacity. This does not affect length v
.
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.
resize_with vec f size
resizes vector vec
up to size
, fills vector with calls to f
on indexes [vec.size-1.. size - 1]
. The contents and size of vec are untouched if size
is inferior or equal to length vec
.
resize_with_init vec init size
resizes vector vec
up to size
, fills vector with calls to init
on indexes [length vec -1.. size - 1]
. The contents and size of vec are untouched if size
is inferior or equal to length vec
.
Append content of iterator. Renamed from append_std_seq
since 3.0.
Raised on empty stack.
Truncate to the given size (remove elements above this size). Does nothing if the parameter is bigger than the current size. truncate
was called shrink
.
Is the element a member of the vector?
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.
Sort the vector in place (modifying it). This function change the size of the underlying array.
Sort the array and remove duplicates, in place (e.g. modifying the vector itself).
Map elements of the vector, yielding a new vector.
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
.
Filter elements from the vector. filter p v
leaves v
unchanged but returns a new vector that only contains elements of v
satisfying p
.
Filter elements from the vector in place.
foldi f init v
is just like fold
, but it also passes in the index of each element as the first argument to the function f
.
Existential test (is there an element that satisfies the predicate?).
Universal test (do all the elements satisfy the predicate?).
Find an element that satisfies the predicate.
Find an element that satisfies the predicate, or
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
.
Map elements with a function, possibly filtering some of them out.
Filter-map elements of the vector in place
Map each element to a sub-vector.
Like flat_map
, but using Seq
for intermediate collections. Renamed from flat_map_std_seq
since 3.0.
Like flat_map
, but using list
for intermediate collections.
All combinaisons of tuples from the two vectors are passed to the function.
remove_and_shift v i
remove the i-th
element from v
. Move elements that are after the i-th
in v
, in linear time. Preserve the order of the elements in v
. See remove_unordered
for constant time removal function that doesn't preserve the order of elements.
remove_unordered v i
remove the i-th
element from v
. Does NOT preserve the order of the elements in v
(might swap with the last element). See remove_and_shift
if you want to keep the ordering.
insert v i x
insert the given element at index i. Elements at location i
and later are first shifted over in linear time before inserting x
. Preserve the order of elements in v
.
rev_iter f a
is the same as iter f (rev a)
, only more efficient.
Number of elements the vector can contain without being resized.
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!).
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]
.
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]
.
of_array a
returns a vector corresponding to the array a
. Operates in O(n)
time.
to_array v
returns an array corresponding to the vector v
.
Convert an Iterator to a vector. Renamed from of_std_seq
since 3.0.
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.
Return an iterator with the elements contained in the vector. Renamed from to_std_seq
since 3.0.
to_seq v
returns the sequence of elements of v
in reverse order, that is, the last elements of v
are iterated on first. Renamed from to_std_seq
since 3.0.
Vector as an array slice. By doing it we expose the internal array, so be careful!.
slice_iter v start len
is the sequence of elements from v.(start)
to v.(start+len-1)
.
val to_string :
?start:string ->
?stop:string ->
?sep:string ->
('a -> string) ->
('a, _) t ->
string
Print the vector in a string
val pp :
?pp_start:unit printer ->
?pp_stop:unit printer ->
?pp_sep:unit printer ->
'a printer ->
('a, _) t printer
pp ~pp_start ~pp_stop ~pp_sep pp_item ppf v
formats the vector v
on ppf
. Each element is formatted with pp_item
, pp_start
is called at the beginning, pp_stop
is called at the end, pp_sep
is called between each elements. By defaults pp_start
and pp_stop
does nothing and pp_sep
defaults to (fun out -> Format.fprintf out ",@ ").