Module CCVector
Growable, mutable vector
type 'a gen= unit -> 'a optiontype 'a equal= 'a -> 'a -> booltype 'a ord= 'a -> 'a -> inttype 'a printer= Stdlib.Format.formatter -> 'a -> unit
val create_with : ?capacity:int -> 'a -> ('a, rw) tCreate a new vector, the value is used to enforce the type the new vector.
- parameter capacity
the size of the underlying array.
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 clear_and_reset : ('a, rw) t -> unitClear the content of the vector, and deallocate the underlying array, removing references to all the elements.
- since
- 2.8
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 to enforce the type of the vector (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 append_seq : ('a, rw) t -> 'a Stdlib.Seq.t -> unitAppend content of iterator. Renamed from
append_std_seqsince 3.0.- since
- 3.0
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 truncate : ('a, rw) t -> int -> unitTruncate to the given size (remove elements above this size). Does nothing if the parameter is bigger than the current size.
truncatewas calledshrink.- since
- 3.0
val shrink_to_fit : ('a, _) t -> unitShrink internal array to fit the size of the vector
- since
- 2.8
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. The underlying array of the new vector can be smaller than the original one.
val sort' : ('a -> 'a -> int) -> ('a, rw) t -> unitSort the vector in place (modifying it). This function change the size of the underlying array.
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 mapi : (int -> 'a -> 'b) -> ('a, _) t -> ('b, 'mut) tmap f vis just likemap, but it also passes in the index of each element as the first argument to the functionf.- since
- 2.8
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 filter_in_place : ('a -> bool) -> ('a, rw) t -> unitFilter elements from the vector in place.
- since
- 3.0
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 Stdlib.Seq.t) -> ('a, _) t -> ('b, 'mut) tLike
flat_map, but usingSeqfor intermediate collections. Renamed fromflat_map_std_seqsince 3.0.- since
- 3.0
val flat_map_list : ('a -> 'b list) -> ('a, _) t -> ('b, 'mut) tLike
flat_map, but usinglistfor intermediate collections.- since
- 0.14
val monoid_product : ('a -> 'b -> 'c) -> ('a, _) t -> ('b, _) t -> ('c, _) tAll combinaisons of tuples from the two vectors are passed to the function.
- since
- 2.8
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_and_shift : ('a, rw) t -> int -> unitremove_and_shift v iremove thei-thelement fromv. Move elements that are after thei-thinv. Preserve the order of the elements inv. Seeremove_unorderedfor constant time function.- since
- 3.0
val remove_unordered : ('a, rw) t -> int -> unitremove_unordered v iremove thei-thelement fromv. Does NOT preserve the order of the elements inv(might swap with the last element). Seeremove_and_shiftif you want to keep the ordering.
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 Stdlib.Seq.t -> ('a, rw) tConvert an Iterator to a vector. Renamed from
of_std_seqsince 3.0.- since
- 3.0
val to_iter_rev : ('a, _) t -> 'a iterto_iter_rev vreturns the sequence of elements ofvin reverse order, that is, the last elements ofvare iterated on first.- since
- 2.8
val to_seq : ('a, _) t -> 'a Stdlib.Seq.tReturn an iterator with the elements contained in the vector. Renamed from
to_std_seqsince 3.0.- since
- 3.0
val to_seq_rev : ('a, _) t -> 'a Stdlib.Seq.tto_seq vreturns the sequence of elements ofvin reverse order, that is, the last elements ofvare iterated on first. Renamed fromto_std_seqsince 3.0.- since
- 3.0
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_iter : ('a, _) t -> int -> int -> 'a iterslice_iter v start lenis the sequence of elements fromv.(start)tov.(start+len-1).- since
- 3.0
val of_gen : ?init:('a, rw) t -> 'a gen -> ('a, rw) tval to_gen : ('a, _) t -> 'a genval to_string : ?start:string -> ?stop:string -> ?sep:string -> ('a -> string) -> ('a, _) t -> stringPrint the vector in a string
- since
- 2.7
val pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> 'a printer -> ('a, _) t printerpp ~pp_start ~pp_stop ~pp_sep pp_item ppf vformats the vectorvonppf. Each element is formatted withpp_item,pp_startis called at the beginning,pp_stopis called at the end,pp_sepis called between each elements. By defaultspp_startandpp_stopdoes nothing andpp_sepdefaults to (fun out -> Format.fprintf out ",@ ").
Let operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8