mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
fix(vector): bugfix in filter
This commit is contained in:
parent
7f1c6ae66f
commit
1998ed5090
1 changed files with 11 additions and 5 deletions
|
|
@ -471,13 +471,13 @@ let filter' p v =
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let filter p v =
|
let filter p v =
|
||||||
if array_is_empty_ v
|
if array_is_empty_ v then (
|
||||||
then create ()
|
create ()
|
||||||
else (
|
) else (
|
||||||
let v' = create_with ~capacity:v.size v.vec.(0) in
|
let v' = create_with ~capacity:v.size v.vec.(0) in
|
||||||
Array.iter
|
iter
|
||||||
(fun x -> if p x then push_unsafe_ v' x)
|
(fun x -> if p x then push_unsafe_ v' x)
|
||||||
v.vec;
|
v;
|
||||||
v'
|
v'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -486,6 +486,12 @@ let filter p v =
|
||||||
filter (fun x-> x mod 2=0) (1 -- 1_000_000) |> length = 500_000
|
filter (fun x-> x mod 2=0) (1 -- 1_000_000) |> length = 500_000
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
(*$QR
|
||||||
|
Q.(pair (fun1 Observable.int bool) (small_list small_int)) (fun (Q.Fun (_,f),l) ->
|
||||||
|
let v = of_list l in
|
||||||
|
to_list (filter f v) = List.filter f l)
|
||||||
|
*)
|
||||||
|
|
||||||
let fold f acc v =
|
let fold f acc v =
|
||||||
let rec fold acc i =
|
let rec fold acc i =
|
||||||
if i = v.size then acc
|
if i = v.size then acc
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue