Module BatArray.Cap
Source Capabilities for arrays.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.
Only the capability-specific functions are documented here. See the complete Array
module for the documentation of other functions.
Source type ('a, 'b) 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.
Base operationsSource val length : ('a , [> ] ) t -> int
Source val get : ('a , [> `Read ] ) t -> int -> 'a
Source val set : ('a , [> `Write ] ) t -> int -> 'a -> unit
ConstructorsSource val make : int -> 'a -> ('a , _ ) t
Source val create : int -> 'a -> ('a , _ ) t
Source val make_float : int -> (float, _ ) t
Array.make_float n
returns a fresh float array of length n
, with uninitialized data.
Source 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.
Source 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.
Source val read_only : ('a , [> `Read ] ) t -> ('a , [ `Read ] ) t
Drop to read-only permissions.
This operation involves no copying.
Source val write_only : ('a , [> `Write ] ) t -> ('a , [ `Write ] ) t
Drop to write-only permissions.
This operation involves no copying.
Source val init : int -> (int -> 'a ) -> ('a , _ ) t
Source val make_matrix : int -> int -> 'a -> (('a , _ ) t , _ ) t
Source val create_matrix : int -> int -> 'a -> (('a , _ ) t , _ ) t
IteratorsSource val iter : ('a -> unit) -> ('a , [> `Read ] ) t -> unit
Source val map : ('a -> 'b ) -> ('a , [> `Read ] ) t -> ('b , _ ) t
Source val iteri : (int -> 'a -> unit) -> ('a , [> `Read ] ) t -> unit
Source val mapi : (int -> 'a -> 'b ) -> ('a , [> `Read ] ) t -> ('b , _ ) t
Source val modify : ('a -> 'a ) -> ('a , [ `Read | `Write ] ) t -> unit
Source val modifyi : (int -> 'a -> 'a ) -> ('a , [ `Read | `Write ] ) t -> unit
Source val fold_left : ('a -> 'b -> 'a ) -> 'a -> ('b , [> `Read ] ) t -> 'a
Source val fold : ('a -> 'b -> 'a ) -> 'a -> ('b , [> `Read ] ) t -> 'a
Source val fold_right : ('b -> 'a -> 'a ) -> ('b , [> `Read ] ) t -> 'a -> 'a
Source val fold_while :
('acc -> 'a -> bool) ->
('acc -> 'a -> 'acc ) ->
'acc ->
('a , [> `Read ] ) t ->
'acc * int
Operations on two arraysSource val iter2 :
('a -> 'b -> unit) ->
('a , [> `Read ] ) t ->
('b , [> `Read ] ) t ->
unit
Source val iter2i :
(int -> 'a -> 'b -> unit) ->
('a , [> `Read ] ) t ->
('b , [> `Read ] ) t ->
unit
PredicatesSource val for_all : ('a -> bool) -> ('a , [> `Read ] ) t -> bool
Source val exists : ('a -> bool) -> ('a , [> `Read ] ) t -> bool
Source val find : ('a -> bool) -> ('a , [> `Read ] ) t -> 'a
Source val find_opt : ('a -> bool) -> ('a , [> `Read ] ) t -> 'a option
Source val find_map : ('a -> 'b option ) -> ('a , [> `Read ] ) t -> 'b option
Source val mem : 'a -> ('a , [> `Read ] ) t -> bool
Source val memq : 'a -> ('a , [> `Read ] ) t -> bool
Source val findi : ('a -> bool) -> ('a , [> `Read ] ) t -> int
Source val filter : ('a -> bool) -> ('a , [> `Read ] ) t -> ('a , _ ) t
Source val filter_map : ('a -> 'b option ) -> ('a , [> `Read ] ) t -> ('b , _ ) t
Source val count_matching : ('a -> bool) -> ('a , [> `Read ] ) t -> int
Source val find_all : ('a -> bool) -> ('a , [> `Read ] ) t -> ('a , _ ) t
Source val partition : ('a -> bool) -> ('a , [> `Read ] ) t -> ('a , _ ) t * ('a , _ ) t
Source val rev : ('a , [> `Read ] ) t -> ('a , _ ) t
Source val rev_in_place : ('a , [ `Read | `Write ] ) t -> unit
Source val append : ('a , [> `Read ] ) t -> ('a , [> `Read ] ) t -> ('a , _ ) t
Source val concat : ('a , [> `Read ] ) t list -> ('a , _ ) t
Source val sub : ('a , [> `Read ] ) t -> int -> int -> ('a , _ ) t
Source val copy : ('a , [> `Read ] ) t -> 'a array
Source val fill : ('a , [> `Write ] ) t -> int -> int -> 'a -> unit
Source val blit :
('a , [> `Read ] ) t ->
int ->
('a , [> `Write ] ) t ->
int ->
int ->
unit
ConversionsSource val to_list : ('a , [> `Read ] ) t -> 'a list
Source val split : ('a * 'b , [> `Read ] ) t -> ('a , _ ) t * ('b , _ ) t
Source val combine :
('a , [> `Read ] ) t ->
('b , [> `Read ] ) t ->
('a * 'b , [> `Read ] ) t
Source val of_list : 'a list -> ('a , _ ) t
UtilitiesSource val sort : ('a -> 'a -> int) -> ('a , [> `Read | `Write ] ) t -> unit
Source val stable_sort : ('a -> 'a -> int) -> ('a , [ `Read | `Write ] ) t -> unit
Source val fast_sort : ('a -> 'a -> int) -> ('a , [ `Read | `Write ] ) t -> unit
Boilerplate code Override modules