From 2faa3fbae5480a4c4964512488cd60f4951df513 Mon Sep 17 00:00:00 2001 From: Fardale Date: Mon, 27 Apr 2020 13:29:20 +0200 Subject: [PATCH] chore(CCVector): rename remove to remove_and_shift --- src/core/CCVector.ml | 10 +++++----- src/core/CCVector.mli | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/CCVector.ml b/src/core/CCVector.ml index 6029d834..8adb0758 100644 --- a/src/core/CCVector.ml +++ b/src/core/CCVector.ml @@ -247,7 +247,7 @@ let set v i x = if i < 0 || i >= v.size then invalid_arg "CCVector.set"; Array.unsafe_set v.vec i x -let remove v i = +let remove_and_shift v i = if i < 0 || i >= v.size then invalid_arg "CCVector.remove"; (* if v.(i) not the last element, then put last element at index i *) if i < v.size - 1 @@ -265,21 +265,21 @@ let remove_unordered v i = v.size <- v.size - 1; fill_with_junk_ v.vec v.size 1 -(*$Q remove +(*$Q remove_and_shift Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \ let v1 = of_list l and v2 = of_list l in \ - remove v1 9; \ + remove_and_shift v1 9; \ remove_unordered v2 9; \ to_list v1 = (to_list v2)) Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \ let l = List.sort CCInt.compare l in \ let v = of_list l in\ - remove v 3; \ + remove_and_shift v 3; \ to_list v = (List.sort CCInt.compare (to_list v))) Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \ let l = List.sort CCInt.compare l in \ let v1 = of_list l and v2 = of_list l in \ - remove v1 3; \ + remove_and_shift v1 3; \ remove_unordered v2 3; \ to_list v1 = (List.sort CCInt.compare (to_list v2))) *) diff --git a/src/core/CCVector.mli b/src/core/CCVector.mli index c77df09b..6d3030e8 100644 --- a/src/core/CCVector.mli +++ b/src/core/CCVector.mli @@ -234,7 +234,7 @@ val set : ('a, rw) t -> int -> 'a -> unit (** Modify element at given index, or @raise Invalid_argument if bad index. *) -val remove : ('a, rw) t -> int -> unit +val remove_and_shift : ('a, rw) t -> int -> unit (** [remove v i] remove the [i-th] element from [v]. Move elements that are after the [i-th] in [v]. Preserve the order of the elements in [v]. @@ -243,7 +243,8 @@ val remove : ('a, rw) t -> int -> unit val remove_unordered : ('a, rw) t -> int -> unit (** [remove_unordered v i] remove the [i-th] element from [v]. Does {b NOT} preserve the order of the elements in [v] - (might swap with the last element). *) + (might swap with the last element). + See {!remove_and_shift} if you want to keep the ordering. *) val rev : ('a,_) t -> ('a, 'mut) t (** Reverse the vector. *)