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~1and default valuedflt. Theszargument, which must be non-negative, is used as a hint of the potential range of indices. This function raises theSizeexception 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 inarrin the range[lo, hi]. This function raises theSizeexception iflo < 0orhi < lo-1. val fromList : 'a list * 'a -> 'a array-
fromList (lst, dflt)returns a new array created from the elements oflstand 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 ofvecand with default valuedflt. The bound of the array will belength vec - 1. val toList : 'a array -> 'a list-
toList arrreturns 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 arrreturns 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 firstszelements initialized using the functioninitand the default valuedflt. This function raises theSizeexception ifsz < 0. val default : 'a array -> 'a-
default arrreturns 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 theSubscriptexception ifix < 0. val update : ('a array * int * 'a) -> unit-
update (arr, ix, v)sets the value at indexixof the array tov. Ifixis greater than the current bound of the array, then the bound is set toix. This function raises theSubscriptexception ifix < 0. val bound : 'a array -> int-
bound arrreturns 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 toszto the array’s default value. val appi : (int * 'a -> unit) -> 'a array -> unit-
appi f arrbehaves like theArray.appifunction on the defined range ofarr. val app : ('a -> unit) -> 'a array -> unit-
app f arrbehaves like theArray.appfunction on the defined range ofarr. val modifyi : (int * 'a -> 'a) -> 'a array -> unit-
modifyi f arrbehaves like theArray.modifyifunction on the defined range ofarr. val modify : ('a -> 'a) -> 'a array -> unit-
modify f arrbehaves like theArray.modifyfunction on the defined range ofarr. val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b-
foldli f init arrbehaves like theArray.foldlifunction on the defined range ofarr. val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a array -> 'b-
foldri f init arrbehaves like theArray.foldrifunction on the defined range ofarr. val foldl : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b-
foldl f init arrbehaves like theArray.foldlfunction on the defined range ofarr. val foldr : ('a * 'b -> 'b) -> 'b -> 'a array -> 'b-
foldr f init arrbehaves like theArray.foldrfunction on the defined range ofarr. val findi : (int * 'a -> bool) -> 'a array -> (int * 'a) option-
findi f arrbehaves like theArray.findifunction on the defined range ofarr. val find : ('a -> bool) -> 'a array -> 'a option-
find f arrbehaves like theArray.findfunction on the defined range ofarr. val exists : ('a -> bool) -> 'a array -> bool-
exists f arrbehaves like theArray.existsfunction on the defined range ofarr. val all : ('a -> bool) -> 'a array -> bool-
all f arrbehaves like theArray.allfunction 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 comparisoncmpon elements.
Deprecated functions
val vector : 'a array -> 'a vector-
Use
toVectorinstead.