mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-06 11:15:43 -05:00
feat(util): add Vec_sig to express common vector interface
This commit is contained in:
parent
3fbb9af664
commit
c8eb1ec29e
5 changed files with 35 additions and 53 deletions
|
|
@ -6,6 +6,7 @@ module Util = Util
|
|||
module Vec = Vec
|
||||
module VecI32 = VecI32
|
||||
module Vec_float = Vec_float
|
||||
module Vec_sig = Vec_sig
|
||||
module Bitvec = Bitvec
|
||||
|
||||
module IArray = IArray
|
||||
|
|
|
|||
|
|
@ -3,37 +3,13 @@
|
|||
|
||||
These vectors are more optimized than {!Vec}. *)
|
||||
|
||||
type t
|
||||
|
||||
val create : ?cap:int -> unit -> t
|
||||
include Vec_sig.S with type elt := int
|
||||
|
||||
val ensure_size : t -> int -> unit
|
||||
|
||||
val size : t -> int
|
||||
|
||||
val clear : t -> unit
|
||||
|
||||
val is_empty : t -> bool
|
||||
|
||||
val push : t -> int -> unit
|
||||
|
||||
val pop : t -> int
|
||||
|
||||
val push_i32 : t -> int32 -> unit
|
||||
|
||||
val get : t -> int -> int
|
||||
|
||||
val get_i32 : t -> int -> int32
|
||||
|
||||
val set : t -> int -> int -> unit
|
||||
|
||||
val set_i32 : t -> int -> int32 -> unit
|
||||
|
||||
val shrink : t -> int -> unit
|
||||
|
||||
val iter : f:(int -> unit) -> t -> unit
|
||||
val iteri : f:(int -> int -> unit) -> t -> unit
|
||||
|
||||
val to_iter : t -> int Iter.t
|
||||
|
||||
val pp : t CCFormat.printer
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ type t = {
|
|||
|
||||
let mk_arr_ sz : float_arr = A.create Bigarray.float64 Bigarray.c_layout sz
|
||||
|
||||
let create () : t =
|
||||
{ sz=0; data=mk_arr_ 16 }
|
||||
let create ?(cap=16) () : t =
|
||||
{ sz=0; data=mk_arr_ cap }
|
||||
|
||||
let[@inline] clear self = self.sz <- 0
|
||||
let[@inline] shrink self n = if n < self.sz then self.sz <- n
|
||||
|
|
|
|||
|
|
@ -3,31 +3,6 @@
|
|||
|
||||
These vectors are more optimized than {!Vec}. *)
|
||||
|
||||
type t
|
||||
|
||||
val create : unit -> t
|
||||
include Vec_sig.S with type elt := float
|
||||
|
||||
val ensure_size : t -> int -> unit
|
||||
|
||||
val size : t -> int
|
||||
|
||||
val clear : t -> unit
|
||||
|
||||
val is_empty : t -> bool
|
||||
|
||||
val push : t -> float -> unit
|
||||
|
||||
val pop : t -> float
|
||||
|
||||
val get : t -> int -> float
|
||||
|
||||
val set : t -> int -> float -> unit
|
||||
|
||||
val shrink : t -> int -> unit
|
||||
|
||||
val iter : f:(float -> unit) -> t -> unit
|
||||
val iteri : f:(int -> float -> unit) -> t -> unit
|
||||
|
||||
val to_iter : t -> float Iter.t
|
||||
|
||||
val pp : t CCFormat.printer
|
||||
|
|
|
|||
30
src/util/Vec_sig.ml
Normal file
30
src/util/Vec_sig.ml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
module type S = sig
|
||||
type elt
|
||||
type t
|
||||
|
||||
val create : ?cap:int -> unit -> t
|
||||
|
||||
val size : t -> int
|
||||
|
||||
val clear : t -> unit
|
||||
|
||||
val is_empty : t -> bool
|
||||
|
||||
val push : t -> elt -> unit
|
||||
|
||||
val pop : t -> elt
|
||||
|
||||
val get : t -> int -> elt
|
||||
|
||||
val set : t -> int -> elt -> unit
|
||||
|
||||
val shrink : t -> int -> unit
|
||||
|
||||
val iter : f:(int -> unit) -> t -> unit
|
||||
val iteri : f:(int -> elt -> unit) -> t -> unit
|
||||
|
||||
val to_iter : t -> elt Iter.t
|
||||
|
||||
val pp : t CCFormat.printer
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue