Library
Module
Module type
Parameter
Class
Class type
val make : int -> 'a -> 'a t
make n x
returns a fresh array of length n
, initialized with x
. Each element of the array is a fresh copy of a
. This is different from Array.make
val init : int -> (int -> 'a) -> 'a t
init n f
returns a fresh array of length n
, with element number i
initialized to the result of f i
. In other terms, init n f
tabulates the results of f
applied to the integers 0
to n-1
.
val of_array : 'a array -> 'a t
of_array a
builds a C array with the same content than the Caml array a
val to_array : 'a t -> 'a array
to_array a
returns a Caml array with the same content than the C array a
val of_list : 'a list -> 'a t
of_list l
returns a C array with the same content than the list l
val to_list : 'a t -> 'a list
to_list a
returns a Caml list with the same content than the array a
val set : 'a t -> 'a -> int -> unit
set a n x
modifies array a
in place, replacing element number n
with x
val get : 'a t -> int -> 'a
get a n
gets an returns the element number n
of the array a
. The first element has number 0
. The last element has number length length -
1
.
val length : 'a t -> int
Return the length (number of elements) of the given array
sub a pos len
returns a fresh array of length len
, containing the elements number pos
to pos + len - 1
of array a
.
sub_noalloc a pos len
is the same than sub
but does not perform allocation. The elements of the output are physically the same than the input. Consequently, modifying the elements of the input will modify the output, and inversely.
val iter : ('a -> unit) -> 'a t -> unit
iter f a
iterates f
over a
val iteri : (int -> 'a -> unit) -> 'a t -> unit
Same as iter
, but the function is applied to the index of the element as first argument, and the element itself as second argument
val for_all : ('a -> bool) -> 'a t -> bool
for_all f a
checks if all elements of the array satisfy the predicate f
map f a
applies function f
to all the elements of a
, and builds an array with the results returned by f
: [| f a.(0); f a.(1); ...; f
a.(length a - 1) |]
.
append v1 v2
returns a fresh array containing the concatenation of the arrays v1
and v2
.
Raises Invalid_argument
if length v1 + length v2 >
Sys.max_array_length
val fill : 'a t -> int -> int -> 'a -> unit
fill a pos len x
modifies the array a
in place, storing x
in elements number pos
to pos + len - 1
.
Raises Invalid_argument
if pos
and len
do not designate a valid subarray of a
.
blit src src_pos dst dst_pos len
copies len
elements from array src
, starting at element number src_pos
, to array dst
, starting at element number dst_pos
. It works correctly even if src
and dst
are the same array, and the source and destination chunks overlap.
Raises Invalid_argument
if src_pos
and len
do not designate a valid subarray of src
, or if dst_pos
and len
do not designate a valid subarray of dst
.
val exists : ('a -> bool) -> 'a t -> bool
exists f [|a1; ...; an|]
checks if at least one element of the array satisfies the predicate f
. That is, it returns (f a1) || (f a2) || ... ||
(f an)
.
val mem : 'a -> 'a t -> bool
mem a set
is true
if and only if a is structurally equal to an element of l
(i.e. there is an x
in l
such that compare a x = 0
).