![]() |
![]() |
![]() |
|
Array module provides mutable arrays indexed with integers. Access time is constant. | |
type <'a>t; | |
Type of arrays holding values of type 'a. | |
'a get(<'a>t a, int i); | |
Given an array a and index in it i return value stored at this index. Raise Invalid_argument if i is outside 0 -- Array::length(a)-1. It is constant time operation. | |
void set(<'a>t a, int i, 'a v); | |
Store v in a at position i. Raise Invalid_argument if i is outside 0 -- Array::length(a)-1. It is constant time operation. | |
int length(<'a>t a); | |
Return number of elements in array a. It is constant time operation. | |
<'a>t make(int n, 'a v); | |
Return fresh array of size n, with all elements initialized to v. | |
<'a>t init(int n, *('a (int)) f); | |
Return fresh array of size n with 0th element initialized to f(0), 1st to f(1) and so on. f is called with arguments increasing from 0 to n-1. | |
<'a>t empty(int size_hint); | |
Return array with 0 elements. However size_hint memory cells are allocated for future use (it can be 0). | |
void iter(*(void ('a)) f, <'a>t a); | |
Run function f on each element of array a, from 0 to Array::length(a)-1. | |
<'a>list to_list(<'a>t a); | |
Return list containing all elements of array a. First element of list contains Array::get(a, 0), second Array::get(a, 1) and so on. | |
<'a>t of_list(<'a>list l); | |
Return fresh array containing elements of l. It holds, that to_list(of_list(x)) == x. | |
void resize(<'a>t a, int new_size, 'a v); | |
Resize given array a to new_size elements. New elements (if any) are initialized to v. It is guaranteed that code like for (int i = 0; i < n; i++) resize(foo, i, 0); takes O(n * log(n)) time, but this routine can take O(new_size) time. | |
void really_resize(<'a>t a, int new_size, 'a v); | |
Same as Array::resize, except it allocates exactly number of cells requested, therefore it takes omega(new_size) time. | |
void clear(<'a>t a); | |
Resize a to have 0 elements. | |
void append(<'a>t a, 'a v); | |
Append one element at end of a. Same as Array::resize(a, Array::length(a) + 1, v) but slightly more efficient. | |
void append_array(<'a>t dst, <'a>t src); | |
Append src at end of dst. | |
<'a>t concat(<<'a>t>list al); | |
Return fresh array that is concatenation of all arrays in al. | |
<'a>t concat_sep(<'a>t sep, <<'a>t>list al); | |
Return fresh array that is concatenation of all arrays in al, separated with contents of sep. | |
<'a>t copy(<'a>t src); | |
Return copy of array src. It takes O(Array::length(src)) time. | |
void blit(<'a>t src, int srcoff, <'a>t dst, int dstoff, int len); | |
Copy elements srcoff .. srcoff + len - 1 of src to dst starting from dstoff. Raise Invalid_argument if offsets are out of range. | |
void fill(<'a>t a, int off, int len, 'a v); | |
Set elements off .. off + len - 1 of a to v. Raise Invalid_argument if pos or len are out of range. | |
<'a>t sub(<'a> t a, int off, int len); | |
Return fresh array containing elements of a from off to off + len - 1. Raise Invalid_argument if off or len are out of range. |