mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-15 23:36:01 -05:00
feat(CCVector) remove shrink_to_fit and rename shrink in keep
This commit is contained in:
parent
0fea0ea522
commit
b18ec9d220
2 changed files with 6 additions and 25 deletions
|
|
@ -112,7 +112,7 @@ let resize_ v newcapacity x =
|
||||||
push v 0.; push v 1.;
|
push v 0.; push v 1.;
|
||||||
clear v;
|
clear v;
|
||||||
push v 0.; push v 1.; push v 7.; push v 10.; push v 12.;
|
push v 0.; push v 1.; push v 7.; push v 10.; push v 12.;
|
||||||
shrink v 2;
|
keep v 2;
|
||||||
assert_equal 1. (fold (+.) 0. v);
|
assert_equal 1. (fold (+.) 0. v);
|
||||||
clear v;
|
clear v;
|
||||||
assert_equal 0 (size v);
|
assert_equal 0 (size v);
|
||||||
|
|
@ -433,7 +433,7 @@ let copy v = {
|
||||||
equal (=) v v')
|
equal (=) v v')
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let shrink v n =
|
let keep v n =
|
||||||
let old_size = v.size in
|
let old_size = v.size in
|
||||||
if n < old_size then (
|
if n < old_size then (
|
||||||
v.size <- n;
|
v.size <- n;
|
||||||
|
|
@ -443,7 +443,7 @@ let shrink v n =
|
||||||
|
|
||||||
(*$R
|
(*$R
|
||||||
let v = of_iter Iter.(1 -- 10) in
|
let v = of_iter Iter.(1 -- 10) in
|
||||||
shrink v 5;
|
keep v 5;
|
||||||
OUnit.assert_equal [1;2;3;4;5] (to_list v);
|
OUnit.assert_equal [1;2;3;4;5] (to_list v);
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
@ -453,26 +453,11 @@ let shrink v n =
|
||||||
let l = to_list v in
|
let l = to_list v in
|
||||||
let h = Iter.(to_list (take n (of_list l))) in
|
let h = Iter.(to_list (take n (of_list l))) in
|
||||||
let v' = copy v in
|
let v' = copy v in
|
||||||
shrink v' n;
|
keep v' n;
|
||||||
h = to_list v'
|
h = to_list v'
|
||||||
)
|
)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let shrink_to_fit v : unit =
|
|
||||||
if v.size = 0 then (
|
|
||||||
v.vec <- [| |]
|
|
||||||
) else if v.size < Array.length v.vec then (
|
|
||||||
v.vec <- Array.sub v.vec 0 v.size
|
|
||||||
)
|
|
||||||
|
|
||||||
(*$QR
|
|
||||||
(gen Q.small_int) (fun v ->
|
|
||||||
let v' = copy v in
|
|
||||||
shrink_to_fit v;
|
|
||||||
to_list v = to_list v'
|
|
||||||
)
|
|
||||||
*)
|
|
||||||
|
|
||||||
let sort' cmp v =
|
let sort' cmp v =
|
||||||
(* possibly copy array (to avoid junk at its end), then sort the array *)
|
(* possibly copy array (to avoid junk at its end), then sort the array *)
|
||||||
let a =
|
let a =
|
||||||
|
|
|
||||||
|
|
@ -125,14 +125,10 @@ val top_exn : ('a, _) t -> 'a
|
||||||
val copy : ('a,_) t -> ('a,'mut) t
|
val copy : ('a,_) t -> ('a,'mut) t
|
||||||
(** Shallow copy (may give an immutable or mutable vector). *)
|
(** Shallow copy (may give an immutable or mutable vector). *)
|
||||||
|
|
||||||
val shrink : ('a, rw) t -> int -> unit
|
val keep : ('a, rw) t -> int -> unit
|
||||||
(** Shrink to the given size (remove elements above this size).
|
(** [keep v n] Keep the [n] first elements of [v] and remove the rest.
|
||||||
Does nothing if the parameter is bigger than the current size. *)
|
Does nothing if the parameter is bigger than the current size. *)
|
||||||
|
|
||||||
val shrink_to_fit : ('a, _) t -> unit
|
|
||||||
(** Shrink internal array to fit the size of the vector
|
|
||||||
@since 2.8 *)
|
|
||||||
|
|
||||||
val member : eq:('a -> 'a -> bool) -> 'a -> ('a, _) t -> bool
|
val member : eq:('a -> 'a -> bool) -> 'a -> ('a, _) t -> bool
|
||||||
(** Is the element a member of the vector? *)
|
(** Is the element a member of the vector? *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue