Array.Cap
include module type of struct include BatArray.Cap end
This modules provides the same set of features as Array
, but with the added twist that arrays can be made read-only or write-only. Read-only arrays may then be safely shared and distributed.
There is no loss of performance involved.
type ('a, 'b) t = ('a, 'b) BatArray.Cap.t constraint 'b = [< `Read | `Write ]
The type of arrays with capabilities. An ('a, [`Read | `Write])
array behaves as a regular 'a array
, while a ('a, [`Read]) array
only has read-only capabilities and a ('a, [`Write]) array
only has write-only capabilities.
val length : ('a, [> ]) t -> int
val get : ('a, [> `Read ]) t -> int -> 'a
val set : ('a, [> `Write ]) t -> int -> 'a -> unit
val make : int -> 'a -> ('a, _) t
val create : int -> 'a -> ('a, _) t
val make_float : int -> (float, _) t
Array.make_float n
returns a fresh float array of length n
, with uninitialized data.
val of_array : 'a array -> ('a, _) t
Adopt a regular array as a capability array, allowing to decrease capabilities if necessary.
This operation involves no copying. In other words, in let cap = of_array a in ...
, any modification in a
will also have effect on cap
and reciprocally.
val to_array : ('a, [ `Read | `Write ]) t -> 'a array
Return a capability array as an array.
This operation requires both read and write permissions on the capability array and involves no copying. In other words, in let a = of_array cap in ...
, any modification in a
will also have effect on cap
and reciprocally.
Drop to read-only permissions.
This operation involves no copying.
Drop to write-only permissions.
This operation involves no copying.
val init : int -> (int -> 'a) -> ('a, _) t
val iter : ('a -> unit) -> ('a, [> `Read ]) t -> unit
val iteri : (int -> 'a -> unit) -> ('a, [> `Read ]) t -> unit
val modify : ('a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
val modifyi : (int -> 'a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
val fold_left : ('a -> 'b -> 'a) -> 'a -> ('b, [> `Read ]) t -> 'a
val fold : ('a -> 'b -> 'a) -> 'a -> ('b, [> `Read ]) t -> 'a
val fold_right : ('b -> 'a -> 'a) -> ('b, [> `Read ]) t -> 'a -> 'a
val fold_while : ('acc -> 'a -> bool) -> ('acc -> 'a -> 'acc) -> 'acc -> ('a, [> `Read ]) t -> 'acc * int
val for_all : ('a -> bool) -> ('a, [> `Read ]) t -> bool
val exists : ('a -> bool) -> ('a, [> `Read ]) t -> bool
val mem : 'a -> ('a, [> `Read ]) t -> bool
val memq : 'a -> ('a, [> `Read ]) t -> bool
val count_matching : ('a -> bool) -> ('a, [> `Read ]) t -> int
val rev_in_place : ('a, [ `Read | `Write ]) t -> unit
val copy : ('a, [> `Read ]) t -> 'a array
val fill : ('a, [> `Write ]) t -> int -> int -> 'a -> unit
val to_list : ('a, [> `Read ]) t -> 'a list
val pivot_split : 'a BatOrd.ord -> ('a, [> `Read ]) t -> 'a -> int * int
val of_list : 'a list -> ('a, _) t
val sort : ('a -> 'a -> int) -> ('a, [> `Read | `Write ]) t -> unit
val stable_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
val fast_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
val print : ?first:string -> ?last:string -> ?sep:string ->
('a BatIO.output -> 'b -> unit) -> 'a BatIO.output -> ('b, [> `Read ]) t -> unit
val compare : 'a BatOrd.comp -> ('a, [> `Read ]) t BatOrd.comp
val ord : 'a BatOrd.ord -> ('a, [> `Read ]) t BatOrd.ord
module Exceptionless = BatArray.Cap.Exceptionless
Operations on BatArray.Cap
without exceptions.
module Labels = BatArray.Cap.Labels
Operations on BatArray.Cap
with labels.
include module type of struct include BatArray.Cap.Exceptionless end
Operations on BatArray.Cap
without exceptions.
val find : ('a -> bool) -> ('a, [> `Read ]) BatArray.Cap.t -> 'a option
val findi : ('a -> bool) -> ('a, [> `Read ]) BatArray.Cap.t -> int option