This module implements arrays that automatically expand as necessary. Its implementation uses a traditional array and replaces it with a larger array when needed (and elements are copied from the old array to the new one). The current implementation doubles the capacity when growing the array (and shrinks it whenever the number of elements comes to one fourth of the capacity).
The unused part of the internal array is filled with a dummy value, which is user-provided at creation time (and referred to below as ``the dummy value''). Consequently, vectors do not retain pointers to values that are not used anymore after a shrinking.
Vectors provide an efficient implementation of stacks, with a better locality of reference than list-based implementations (such as standard library Stack). A stack interface is provided, similar to that of Stack (though Vector.push have arguments in the other way round). Inserting n elements with Vector.push has overall complexity O(n) i.e. each insertion has amortized constant time complexity.
type'a t
The polymorphic type of vectors. This is a mutable data type.
Operations proper to vectors, or with a different type and/or semantics than those of module Array
create returns a fresh vector of length 0. All the elements of this new vector are initially physically equal to dummy (in the sense of the == predicate). When capacity is omitted, it defaults to 0.
make dummy n x returns a fresh vector of length n with all elements initialized with x. If dummy is omitted, x is also used as a dummy value for this vector.
init n f returns a fresh vector 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.
Raise Invalid_argument if n < 0 or n > Sys.max_array_length.
The elements that are no longer part of the vector, if any, are internally replaced by the dummy value of vector a, so that they can be garbage collected when possible.
Raise Invalid_argument if n < 0 or n > Sys.max_array_length.
blit a1 o1 a2 o2 len copies len elements from vector a1, starting at element number o1, to vector a2, starting at element number o2. It works correctly even if a1 and a2 are the same vector, and the source and destination chunks overlap.
Raise Invalid_argument "Vector.blit" if o1 and len do not designate a valid subvector of a1, or if o2 and len do not designate a valid subvector of a2.
map f a applies function f to all the elements of a, and builds a fresh vector with the results returned by f.
Note: the dummy value of the returned vector is obtained by applying f to the dummy value of a. If this is not what you want, first create a new vector and then fill it with the value f (get a 0), f (get a 1), etc.