chore(CCVector): rename remove to remove_and_shift

This commit is contained in:
Fardale 2020-04-27 13:29:20 +02:00 committed by Simon Cruanes
parent c8d61a1248
commit 2faa3fbae5
2 changed files with 8 additions and 7 deletions

View file

@ -247,7 +247,7 @@ let set v i x =
if i < 0 || i >= v.size then invalid_arg "CCVector.set"; if i < 0 || i >= v.size then invalid_arg "CCVector.set";
Array.unsafe_set v.vec i x 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 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 v.(i) not the last element, then put last element at index i *)
if i < v.size - 1 if i < v.size - 1
@ -265,21 +265,21 @@ let remove_unordered v i =
v.size <- v.size - 1; v.size <- v.size - 1;
fill_with_junk_ v.vec 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 -> \ Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \
let v1 = of_list l and v2 = of_list l in \ let v1 = of_list l and v2 = of_list l in \
remove v1 9; \ remove_and_shift v1 9; \
remove_unordered v2 9; \ remove_unordered v2 9; \
to_list v1 = (to_list v2)) to_list v1 = (to_list v2))
Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \ Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \
let l = List.sort CCInt.compare l in \ let l = List.sort CCInt.compare l in \
let v = of_list 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))) to_list v = (List.sort CCInt.compare (to_list v)))
Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \ Q.(list_of_size (Gen.int_range 10 10) small_int) (fun l -> \
let l = List.sort CCInt.compare l in \ let l = List.sort CCInt.compare l in \
let v1 = of_list l and v2 = of_list 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; \ remove_unordered v2 3; \
to_list v1 = (List.sort CCInt.compare (to_list v2))) to_list v1 = (List.sort CCInt.compare (to_list v2)))
*) *)

View file

@ -234,7 +234,7 @@ val set : ('a, rw) t -> int -> 'a -> unit
(** Modify element at given index, or (** Modify element at given index, or
@raise Invalid_argument if bad index. *) @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]. (** [remove v i] remove the [i-th] element from [v].
Move elements that are after the [i-th] in [v]. Move elements that are after the [i-th] in [v].
Preserve the order of the elements 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 val remove_unordered : ('a, rw) t -> int -> unit
(** [remove_unordered v i] remove the [i-th] element from [v]. (** [remove_unordered v i] remove the [i-th] element from [v].
Does {b NOT} preserve the order of the elements in [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 val rev : ('a,_) t -> ('a, 'mut) t
(** Reverse the vector. *) (** Reverse the vector. *)