mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-08 04:05:43 -05:00
feat(vec): add copy
This commit is contained in:
parent
5e0652687a
commit
313e9db026
5 changed files with 22 additions and 4 deletions
|
|
@ -18,6 +18,15 @@ let[@inline] shrink self n = if n < self.sz then self.sz <- n
|
||||||
let[@inline] size self = self.sz
|
let[@inline] size self = self.sz
|
||||||
let[@inline] is_empty self = self.sz = 0
|
let[@inline] is_empty self = self.sz = 0
|
||||||
|
|
||||||
|
let copy self =
|
||||||
|
if size self=0 then create ~cap:0 ()
|
||||||
|
else (
|
||||||
|
(* copy bigarray *)
|
||||||
|
let data = mk_arr_ (size self) in
|
||||||
|
A.blit self.data data;
|
||||||
|
{sz=self.sz; data}
|
||||||
|
)
|
||||||
|
|
||||||
let[@inline] fast_remove t i =
|
let[@inline] fast_remove t i =
|
||||||
assert (i>= 0 && i < t.sz);
|
assert (i>= 0 && i < t.sz);
|
||||||
A.unsafe_set t.data i @@ A.unsafe_get t.data (t.sz - 1);
|
A.unsafe_set t.data i @@ A.unsafe_get t.data (t.sz - 1);
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
include Vec_sig.S with type elt := int
|
include Vec_sig.S with type elt := int
|
||||||
|
|
||||||
val ensure_size : t -> int -> unit
|
|
||||||
|
|
||||||
val push_i32 : t -> int32 -> unit
|
val push_i32 : t -> int32 -> unit
|
||||||
|
|
||||||
val get_i32 : t -> int -> int32
|
val get_i32 : t -> int -> int32
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,15 @@ let[@inline] shrink self n = if n < self.sz then self.sz <- n
|
||||||
let[@inline] size self = self.sz
|
let[@inline] size self = self.sz
|
||||||
let[@inline] is_empty self = self.sz = 0
|
let[@inline] is_empty self = self.sz = 0
|
||||||
|
|
||||||
|
let copy self =
|
||||||
|
if size self=0 then create ~cap:0 ()
|
||||||
|
else (
|
||||||
|
(* copy bigarray *)
|
||||||
|
let data = mk_arr_ (size self) in
|
||||||
|
A.blit self.data data;
|
||||||
|
{sz=self.sz; data}
|
||||||
|
)
|
||||||
|
|
||||||
let[@inline] fast_remove t i =
|
let[@inline] fast_remove t i =
|
||||||
assert (i>= 0 && i < t.sz);
|
assert (i>= 0 && i < t.sz);
|
||||||
A.unsafe_set t.data i @@ A.unsafe_get t.data (t.sz - 1);
|
A.unsafe_set t.data i @@ A.unsafe_get t.data (t.sz - 1);
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,3 @@
|
||||||
These vectors are more optimized than {!Vec}. *)
|
These vectors are more optimized than {!Vec}. *)
|
||||||
|
|
||||||
include Vec_sig.S with type elt := float
|
include Vec_sig.S with type elt := float
|
||||||
|
|
||||||
val ensure_size : t -> int -> unit
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ module type BASE = sig
|
||||||
|
|
||||||
val clear : t -> unit
|
val clear : t -> unit
|
||||||
|
|
||||||
|
val copy : t -> t
|
||||||
|
|
||||||
val is_empty : t -> bool
|
val is_empty : t -> bool
|
||||||
|
|
||||||
val push : t -> elt -> unit
|
val push : t -> elt -> unit
|
||||||
|
|
@ -29,6 +31,8 @@ module type BASE = sig
|
||||||
|
|
||||||
val filter_in_place : (elt -> bool) -> t -> unit
|
val filter_in_place : (elt -> bool) -> t -> unit
|
||||||
|
|
||||||
|
val ensure_size : t -> int -> unit
|
||||||
|
|
||||||
val pop : t -> elt
|
val pop : t -> elt
|
||||||
|
|
||||||
val set : t -> int -> elt -> unit
|
val set : t -> int -> elt -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue