package varray

  1. Overview
  2. Docs

The array will be used partially, with some elements in an undefined state. It is guaranteed that all operations always use valid indexes.

type 'a t

The type of an array.

type 'a elt

The type of elements contained in the array.

val length : 'a t -> int

The size of the array; the maximum number of elements that can be stored inside.

val empty : unit -> 'a t

An empty array of length 0.

val create : int -> 'a t

create n returns an array of length n. Its elements are all in an undefined state and will not be accessed by get before being defined by set or blit.

val get : 'a t -> int -> 'a elt

get t i returns the ith element of the array. The elements are numbered from 0 to length t - 1 and the index i is always within this bound: this function can be implemented as an unsafe_get) if available.

val set : 'a t -> int -> 'a elt -> unit

set t i v modifies t in place, replacing the element at position i with the value v. From now on, the element at this index is defined. Again, this can be implemented as an unsafe_set without bound checking.

val erase_at : 'a t -> int -> unit

erase_at t i resets the element at position i. It is an opportunity to free the memory of the value t.(i). From now on, the element is undefined and this index will not be accessed again until a write is done.

val blit : 'a t -> int -> 'a t -> int -> int -> unit

blit src i dst j n copies the elements from the range i,i+n-1 from the array src to the range j,j+n-1 of the array dst. All the elements copied from src are guaranteed to be in a defined state. After this operation, the corresponding range in dst will be defined. The copied ranges will be valid for each array. Special care is required during the copy since src will often be the same array as dst and the ranges can overlap.

OCaml

Innovation. Community. Security.