package carray
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Carray
Source
The type of C arrays
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
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
.
of_array a
builds a C array with the same content than the Caml array a
to_array a
returns a Caml array with the same content than the C array a
of_list l
returns a C array with the same content than the list l
to_list a
returns a Caml list with the same content than the array a
set a n x
modifies array a
in place, replacing element number n
with x
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
.
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.
Same as iter
, but the function is applied to the index of the element as first argument, and the element itself as second argument
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
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
.
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)
.