module ExtendableArray:sig..end
Extendable arrays are commonly defined by two dimensions: their length and capacity. The first dimension tells how many elements are currently actually stored in the array, while the second dimension tells how many elements could be stored in the array without having to redimension (and hence reallocate) it.
Extendable arrays store elements in the same way as array (i. e. at the lowest indexes), as opposed to sparse arrays.
The present implementation uses Utils.u2 indexes, thus having a
maximum length of 65536.
type 'a t
val make : int -> int -> 'a -> 'a tmake len cap init returns an extendable array with an initial
length of len and capacity cap, each element being initialized to
init.
Raises Invalid_argument if the passed length or capacity is too
large, or negative.val from_array : exn -> 'a array -> 'a -> 'a tInvalid_argument if the passed array is too large, or negative.val to_array : 'a t -> 'a arrayval length : 'a t -> intval capacity : 'a t -> intval get : 'a t -> Utils.u2 -> 'aget a i returns the element of a at index i.
Raises Invalid_argument if i is out of bounds.val set : 'a t -> Utils.u2 -> 'a -> unitset a i x changes the element of a at index i to x.
The array is not extended by this operation.
Raises Invalid_argument if i is out of bounds.val find : ('a -> bool) -> 'a t -> Utils.u2index p a returns the lowest index i of a such that
p (get a i) is true.
Raises Not_found if such an index does not exist.val add : exn -> 'a t -> 'a -> 'a -> bool -> Utils.u2add e a x z addit extends array a by an element set to x.
Returns the index of the added element. addit indicates whether an
unused element z should be added to the array. The z value is
also used to fill the part of the array between its length and its
capacity, if any.
Raises e if the array cannot be extended.val add_if_not_found : exn -> ('a -> bool) -> 'a t -> 'a -> 'a -> bool -> Utils.u2add_if_not_found e p a x z add returns the lowest index i of a
such that p (get a i) is true. If such an index does not exist in
a, a new element x is added to the array.
Equivalent to try find p a with Not_found -> add e a x z addit.
Raises e if the array cannot be extended.val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> boolval compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intval hash : ('a -> int) -> 'a t -> intval to_string : ('a -> string) -> 'a t -> string