Module CCVector
Growable, mutable vector
type 'a sequence= ('a -> unit) -> unittype 'a klist= unit -> [ `Nil | `Cons of 'a * 'a klist ]type 'a gen= unit -> 'a optiontype 'a equal= 'a -> 'a -> booltype 'a ord= 'a -> 'a -> inttype 'a printer= Format.formatter -> 'a -> unit
val create_with : ?capacity:int -> 'a -> ('a, rw) tCreate a new vector, using the given value as a filler.
- parameter capacity
the size of the underlying array. caution: the value will likely not be GC'd before the vector is.
val return : 'a -> ('a, 'mut) tSingleton vector.
- since
- 0.14
val make : int -> 'a -> ('a, 'mut) tmake n xmakes a vector of sizen, filled withx.
val init : int -> (int -> 'a) -> ('a, 'mut) tInit the vector with the given function and size.
val ensure_with : init:'a -> ('a, rw) t -> int -> unitHint to the vector that it should have at least the given capacity.
- parameter init
if
capacity v = 0, used as a filler element for the underlying array (seecreate_with).
- since
- 0.14
val ensure : ('a, rw) t -> int -> unitHint 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
initis not provided.
val is_empty : ('a, _) t -> boolIs the vector empty?
val equal : 'a equal -> ('a, _) t equalval compare : 'a ord -> ('a, _) t ordTotal ordering on vectors. Lexicographic comparison.
val pop_exn : ('a, rw) t -> 'aRemove last element, or raise a Failure if empty.
- raises Empty
on an empty vector.
val top : ('a, _) t -> 'a optionTop element, if present.
- since
- 0.6
val top_exn : ('a, _) t -> 'aTop element, if present.
- raises Empty
on an empty vector.
- since
- 0.6
val shrink : ('a, rw) t -> int -> unitShrink 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 -> boolIs the element a member of the vector?
val sort : ('a -> 'a -> int) -> ('a, _) t -> ('a, 'mut) tSort the vector, returning a copy of it that is sorted w.r.t the given ordering. The vector itself is unchanged.
val uniq_sort : ('a -> 'a -> int) -> ('a, rw) t -> unitSort the array and remove duplicates, in place (e.g. modifying the vector itself).
val iter : ('a -> unit) -> ('a, _) t -> unitIterate on the vector's content.
val iteri : (int -> 'a -> unit) -> ('a, _) t -> unitIterate on the vector, with indexes.
val map_in_place : ('a -> 'a) -> ('a, _) t -> unitMap elements of the vector in place
- since
- 2.3
val filter : ('a -> bool) -> ('a, _) t -> ('a, 'mut) tFilter elements from the vector.
filter p vleavesvunchanged but returns a new vector that only contains elements ofvsatisfyingp.
val fold : ('b -> 'a -> 'b) -> 'b -> ('a, _) t -> 'bFold on elements of the vector
val exists : ('a -> bool) -> ('a, _) t -> boolExistential test (is there an element that satisfies the predicate?).
val for_all : ('a -> bool) -> ('a, _) t -> boolUniversal test (do all the elements satisfy the predicate?).
val find : ('a -> bool) -> ('a, _) t -> 'a optionFind an element that satisfies the predicate.
val find_exn : ('a -> bool) -> ('a, _) t -> 'aFind an element that satisfies the predicate, or
- raises Not_found
if no element does.
val find_map : ('a -> 'b option) -> ('a, _) t -> 'b optionfind_map f vreturns the firstSome y = f xforxinv, orNoneiff x = Nonefor eachxinv.- since
- 0.14
val filter_map : ('a -> 'b option) -> ('a, _) t -> ('b, 'mut) tMap elements with a function, possibly filtering some of them out.
val filter_map_in_place : ('a -> 'a option) -> ('a, _) t -> unitFilter-map elements of the vector in place
- since
- 2.3
val flat_map_seq : ('a -> 'b sequence) -> ('a, _) t -> ('b, 'mut) tLike
flat_map, but usingsequencefor intermediate collections.- since
- 0.14
val flat_map_list : ('a -> 'b list) -> ('a, _) t -> ('b, 'mut) tLike
flat_map, but usinglistfor intermediate collections.- since
- 0.14
val get : ('a, _) t -> int -> 'aAccess element by its index, or
- raises Invalid_argument
if bad index.
val set : ('a, rw) t -> int -> 'a -> unitModify element at given index, or
- raises Invalid_argument
if bad index.
val remove : ('a, rw) t -> int -> unitRemove the
n-thelement of the vector. Does NOT preserve the order of the elements (might swap with the last element).
val rev_iter : ('a -> unit) -> ('a, _) t -> unitrev_iter f ais the same asiter f (rev a), only more efficient.- since
- 0.14
val size : ('a, _) t -> intNumber of elements in the vector.
val capacity : (_, _) t -> intNumber of elements the vector can contain without being resized.
val unsafe_get_array : ('a, rw) t -> 'a arrayAccess the underlying shared array (do not modify!).
unsafe_get_array vis longer thansize v, but elements at higher index thansize vare undefined (do not access!).
val (--) : int -> int -> (int, 'mut) tRange of integers, either ascending or descending (both included, therefore the result is never empty). Example:
1 -- 10returns the vector[1;2;3;4;5;6;7;8;9;10].
val (--^) : int -> int -> (int, 'mut) tRange of integers, either ascending or descending, but excluding right. Example:
1 --^ 10returns the vector[1;2;3;4;5;6;7;8;9].- since
- 0.17
val of_array : 'a array -> ('a, 'mut) tof_array areturns a vector corresponding to the arraya. Operates inO(n)time.
val of_list : 'a list -> ('a, 'mut) tval to_array : ('a, _) t -> 'a arrayto_array vreturns an array corresponding to the vectorv.
val to_list : ('a, _) t -> 'a listReturn a list with the elements contained in the vector.
val of_seq : ?init:('a, rw) t -> 'a sequence -> ('a, rw) tval to_seq : ('a, _) t -> 'a sequenceReturn a
sequencewith the elements contained in the vector.
val to_seq_rev : ('a, _) t -> 'a sequenceto_seq_rev vreturns the sequence of elements ofvin reverse order, that is, the last elements ofvare iterated on first.- since
- 0.14
val slice : ('a, rw) t -> 'a array * int * intVector as an array slice. By doing it we expose the internal array, so be careful!.
val slice_seq : ('a, _) t -> int -> int -> 'a sequenceslice_seq v start lenis the sequence of elements fromv.(start)tov.(start+len-1).
val fill_empty_slots_with : ('a, _) t -> 'a -> unitfill_empty_slots_with v xputsxin the slots ofv's underlying array that are not used (ie in the lastcapacity v - length vslots). This is useful if you removed some elements from the vector and want to be sure they can be GC'd by erasing them from the vector.- since
- 2.4