mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
feat(CCVector): add filter_in_place, deprecate filter'
This commit is contained in:
parent
4bc01a0b82
commit
2b5f2fce11
2 changed files with 13 additions and 5 deletions
|
|
@ -603,7 +603,7 @@ let map_in_place f v =
|
|||
*)
|
||||
|
||||
|
||||
let filter' p v =
|
||||
let filter_in_place p v =
|
||||
let i = ref 0 in (* cur element *)
|
||||
let j = ref 0 in (* cur insertion point *)
|
||||
let n = v.size in
|
||||
|
|
@ -620,15 +620,17 @@ let filter' p v =
|
|||
fill_with_junk_ v.vec !j (v.size - !j);
|
||||
v.size <- !j
|
||||
|
||||
let filter' = filter_in_place
|
||||
|
||||
(*$T
|
||||
let v = 1 -- 10 in filter' (fun x->x<4) v; \
|
||||
let v = 1 -- 10 in filter_in_place (fun x->x<4) v; \
|
||||
to_list v = [1;2;3]
|
||||
*)
|
||||
|
||||
(*$QR
|
||||
Q.(pair (fun1 Observable.int bool) (small_list small_int)) (fun (Q.Fun (_,f),l) ->
|
||||
let v = of_list l in
|
||||
filter' f v;
|
||||
filter_in_place f v;
|
||||
to_list v = List.filter f l)
|
||||
*)
|
||||
|
||||
|
|
@ -791,7 +793,7 @@ let filter_map_in_place f v =
|
|||
let w = Weak.create 1 in
|
||||
Weak.set w 0 (Some s);
|
||||
let v = of_list ["a"; s] in
|
||||
filter' (fun s -> String.length s <= 1) v;
|
||||
filter_in_place (fun s -> String.length s <= 1) v;
|
||||
assert_equal 1 (length v);
|
||||
assert_equal "a" (get v 0);
|
||||
Gc.major();
|
||||
|
|
|
|||
|
|
@ -179,8 +179,14 @@ val filter : ('a -> bool) -> ('a,_) t -> ('a, 'mut) t
|
|||
(** Filter elements from the vector. [filter p v] leaves [v] unchanged but
|
||||
returns a new vector that only contains elements of [v] satisfying [p]. *)
|
||||
|
||||
val filter_in_place : ('a -> bool) -> ('a, rw) t -> unit
|
||||
(** Filter elements from the vector in place.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val filter' : ('a -> bool) -> ('a, rw) t -> unit
|
||||
(** Filter elements in place. *)
|
||||
(** Alias of {!filter_in_place}
|
||||
@deprecated since NEXT_RELEASE, use {!filter_in_place} instead. *)
|
||||
[@@ocaml.deprecated "use filter_in_place instead"]
|
||||
|
||||
val fold : ('b -> 'a -> 'b) -> 'b -> ('a,_) t -> 'b
|
||||
(** Fold on elements of the vector *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue