The DynamicArray
structure provides dynamically sized polymorphic
arrays. Each array has an associated default value, which is
covers those elements that have not been explicitly initialized
(conceptually, one can view an array as having an infinite size).
Thus, reads from indices above the bound will return the default value.
The bound of an array is the highest index of an initialized
element (or ~1
if there are no initialized elements). The
defined range of the array are the elements in the positions
indexed from zero to the bound.
Synopsis
structure DynamicArray
Interface
type 'a array
val array : (int * 'a) -> 'a array
val subArray : ('a array * int * int) -> 'a array
val fromList : 'a list * 'a -> 'a array
val fromVector : 'a vector * 'a -> 'a array
val toList : 'a array -> 'a list
val toVector : 'a array -> 'a vector
val tabulate: (int * (int -> 'a) * 'a) -> 'a array
val default : 'a array -> 'a
val sub : ('a array * int) -> 'a
val update : ('a array * int * 'a) -> unit
val bound : 'a array -> int
val truncate : ('a array * int) -> unit
val appi : (int * 'a -> unit) -> 'a array -> unit
val app : ('a -> unit) -> 'a array -> unit
val modifyi : (int * 'a -> 'a) -> 'a array -> unit
val modify : ('a -> 'a) -> 'a array -> unit
val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b
val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b
val foldl : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
val foldr : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
val findi : (int * 'a -> bool) -> 'a array -> (int * 'a) option
val find : ('a -> bool) -> 'a array -> 'a option
val exists : ('a -> bool) -> 'a array -> bool
val all : ('a -> bool) -> 'a array -> bool
val collate : ('a * 'a -> order) -> 'a array * 'a array -> order
val vector : 'a array -> 'a vector
Description
type 'a array
-
The polymorphic type of dynamic arrays. Each array has a default value and a bound, where the bound is the largest index for which an explicit value has been set. Reads from indices above the bound will return the default value.
val array : (int * 'a) -> 'a array
-
array (sz, dflt)
returns a new array with bound~1
and default valuedflt
. Thesz
argument, which must be non-negative, is used as a hint of the potential range of indices. This function raises theSize
exception ifsz < 0
. val subArray : ('a array * int * int) -> 'a array
-
subArray (arr, lo, hi)
returns a new array with the same default asarr
, and whose values in the range[0, hi-lo]
are equal to the values inarr
in the range[lo, hi]
. This function raises theSize
exception iflo < 0
orhi < lo-1
. val fromList : 'a list * 'a -> 'a array
-
fromList (lst, dflt)
returns a new array created from the elements oflst
and with default valuedflt
. The bound of the array will belength lst - 1
. val fromVector : 'a Vector.vector * 'a -> 'a array
-
fromVector (vec, dflt)
returns a new array created from the elements ofvec
and with default valuedflt
. The bound of the array will belength vec - 1
. val toList : 'a array -> 'a list
-
toList arr
returns a list of the array’s contents. The resulting list will have the array’s bound plus one elements.
val toVector : 'a array -> 'a vector
-
toVector arr
returns a list of the array’s contents. The resulting vector will have the array’s bound plus one elements. val tabulate: (int * (int -> 'a) * 'a) -> 'a array
-
tabulate (sz, init, dflt)
returns a new array with the firstsz
elements initialized using the functioninit
and the default valuedflt
. This function raises theSize
exception ifsz < 0
. val default : 'a array -> 'a
-
default arr
returns the default value for the array. val sub : ('a array * int) -> 'a
-
sub (arr, ix)
returns the value of the array at indexix
. If that value has not been explicitly set, then it returns the array’s default value. This function raises theSubscript
exception ifix < 0
. val update : ('a array * int * 'a) -> unit
-
update (arr, ix, v)
sets the value at indexix
of the array tov
. Ifix
is greater than the current bound of the array, then the bound is set toix
. This function raises theSubscript
exception ifix < 0
. val bound : 'a array -> int
-
bound arr
returns the current bound of the array, which is the highest index that has been explicitly set (e.g., byupdate
). val truncate : ('a array * int) -> unit
-
truncate (arr, sz)
sets every entry with index greater or equal tosz
to the array’s default value. val appi : (int * 'a -> unit) -> 'a array -> unit
-
appi f arr
behaves like theArray.appi
function on the defined range ofarr
. val app : ('a -> unit) -> 'a array -> unit
-
app f arr
behaves like theArray.app
function on the defined range ofarr
. val modifyi : (int * 'a -> 'a) -> 'a array -> unit
-
modifyi f arr
behaves like theArray.modifyi
function on the defined range ofarr
. val modify : ('a -> 'a) -> 'a array -> unit
-
modify f arr
behaves like theArray.modify
function on the defined range ofarr
. val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b
-
foldli f init arr
behaves like theArray.foldli
function on the defined range ofarr
. val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b
-
foldri f init arr
behaves like theArray.foldri
function on the defined range ofarr
. val foldl : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
-
foldl f init arr
behaves like theArray.foldl
function on the defined range ofarr
. val foldr : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
-
foldr f init arr
behaves like theArray.foldr
function on the defined range ofarr
. val findi : (int * 'a -> bool) -> 'a array -> (int * 'a) option
-
findi f arr
behaves like theArray.findi
function on the defined range ofarr
. val find : ('a -> bool) -> 'a array -> 'a option
-
find f arr
behaves like theArray.find
function on the defined range ofarr
. val exists : ('a -> bool) -> 'a array -> bool
-
exists f arr
behaves like theArray.exists
function on the defined range ofarr
. val all : ('a -> bool) -> 'a array -> bool
-
all f arr
behaves like theArray.all
function on the defined range ofarr
. val collate : ('a * 'a -> order) -> 'a array * 'a array -> order
-
collate cmp (arr1, arr2)
return the lexicographic order of the defined ranges of the two arrays using the given comparisoncmp
on elements.
Deprecated functions
val vector : 'a array -> 'a vector
-
Use
toVector
instead.