diff --git a/src/lib_stdlib/ring.ml b/src/lib_stdlib/ring.ml index f57d98f33..a7a633652 100644 --- a/src/lib_stdlib/ring.ml +++ b/src/lib_stdlib/ring.ml @@ -40,6 +40,12 @@ let add_and_return_erased r v = None in add r v ; replaced +let clear r = + match !r with + | Empty _ -> () + | Inited { data ; _ } -> + r := Empty (Array.length data) + let add_list r l = List.iter (add r) l let last r = diff --git a/src/lib_stdlib/ring.mli b/src/lib_stdlib/ring.mli index e67670f19..69b684588 100644 --- a/src/lib_stdlib/ring.mli +++ b/src/lib_stdlib/ring.mli @@ -27,6 +27,9 @@ val add_and_return_erased : 'a t -> 'a -> 'a option (** Adds the values of a list, in order. *) val add_list : 'a t -> 'a list -> unit +(** Removes all values in the ring buffer. *) +val clear : 'a t -> unit + (** Retrieves the most recent value, or [None] when empty. *) val last : 'a t -> 'a option