diff --git a/src/core/CCVector.ml b/src/core/CCVector.ml index 1fa696b8..882a4d35 100644 --- a/src/core/CCVector.ml +++ b/src/core/CCVector.ml @@ -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 = diff --git a/src/core/CCVector.mli b/src/core/CCVector.mli index 24d93821..98e2f202 100644 --- a/src/core/CCVector.mli +++ b/src/core/CCVector.mli @@ -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