feat: add CCVector.clear_and_reset

This commit is contained in:
Simon Cruanes 2019-11-16 17:15:06 -06:00
parent 0ef454c6dc
commit 236a0c43ce
2 changed files with 9 additions and 0 deletions

View file

@ -131,6 +131,10 @@ let clear v =
OUnit.assert_bool "empty_after_clear" (Iter.is_empty (to_seq v));
*)
let clear_and_reset v =
v.size <- 0;
v.vec <- [||]
let is_empty v = v.size = 0
let push_unsafe_ v x =

View file

@ -53,6 +53,11 @@ val init : int -> (int -> 'a) -> ('a, 'mut) t
val clear : ('a, rw) t -> unit
(** Clear the content of the vector. *)
val 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 NEXT_RELEASE *)
val ensure_with : init:'a -> ('a, rw) t -> int -> unit
(** Hint to the vector that it should have at least the given capacity.
@param init if [capacity v = 0], used as a filler