The ArraySlice structure provides an abstraction of subarrays for
polymorphic arrays. A slice value can be viewed as a triple (a, i, n),
where a is the underlying array, i is the starting index, and n is the
length of the subarray, with the constraint that 0 <= i <= i + n <=
|a|. Slices provide a convenient notation for specifying and operating
on a contiguous subset of elements in an array.
structure ArraySlice : ARRAY_SLICE
signature ARRAY_SLICE =
sigtype 'a slice
vallength : 'a slice -> int
valsub : 'a slice * int -> 'a
valupdate : 'a slice * int * 'a -> unit
valfull : 'a Array.array -> 'a slice
valslice : 'a Array.array * int * int option -> 'a slice
valsubslice : 'a slice * int * int option -> 'a slice
valbase : 'a slice -> 'a Array.array * int * int
valvector : 'a slice -> 'a Vector.vectorvalcopy : {
src : 'a slice,
dst : 'a Array.array,
di : int
} -> unit
valcopyVec : {
src : 'a VectorSlice.slice,
dst : 'a Array.array,
di : int
} -> unit
valisEmpty : 'a slice -> bool
valgetItem : 'a slice -> ('a * 'a slice) option
valappi : (int * 'a -> unit) -> 'a slice -> unit
valapp : ('a -> unit) -> 'a slice -> unit
valmodifyi : (int * 'a -> 'a) -> 'a slice -> unit
valmodify : ('a -> 'a) -> 'a slice -> unit
valfoldli : (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b
valfoldri : (int * 'a * 'b -> 'b) -> 'b -> 'a slice -> 'b
valfoldl : ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b
valfoldr : ('a * 'b -> 'b) -> 'b -> 'a slice -> 'b
valfindi : (int * 'a -> bool) -> 'a slice -> (int * 'a) option
valfind : ('a -> bool) -> 'a slice -> 'a option
valexists : ('a -> bool) -> 'a slice -> bool
valall : ('a -> bool) -> 'a slice -> bool
valcollate : ('a * 'a -> order) -> 'a slice * 'a slice -> order
end
creates a slice based on the array arr starting
at index i of the array. If sz is NONE, the slice includes all of the
elements to the end of the array, i.e., arr[i..|arr|-1]. This raises
Subscript if i < 0 or |arr| < i. If sz is SOME(j), the slice has
length j, that is, it corresponds to arr[i..i+j-1]. It raises
Subscript if i < 0 or j < 0 or |arr| < i + j. Note that, if defined,
slice returns an empty slice when i = |arr|.
creates a slice based on the given slice sl
starting at index i of sl. If sz is NONE, the slice includes all of
the elements to the end of the slice, i.e., sl[i..|sl|-1]. This raises
Subscript if i < 0 or |sl| < i. If sz is SOME(j), the slice has length
j, that is, it corresponds to sl[i..i+j-1]. It raises Subscript if i <
0 or j < 0 or |sl| < i + j. Note that, if defined, subslice returns an
empty slice when i = |sl|.
returns a triple (arr, i, n) representing the concrete
representation of the slice. arr is the underlying array, i is the
starting index, and n is the length of the slice.
These functions copy the given slice into the
array dst, with the i(th) element of src, for 0 <= i < |src|, being
copied to position di + i in the destination array. If di < 0 or if
|dst| < di+|src|, then the Subscript exception is raised. The copy
function must correctly handle the case in which dst and the base
array of src are equal, and the source and destination slices overlap.
These functions apply the function f to the elements of a
slice in order of increasing indices. The more general appi function
supplies f with the index of the corresponding element in the
slice. The expression app f sl is equivalent to appi (f o #2) sl.
These functions apply the function f to the elements of
a slice in order of increasing indices, and replace each element with
the result. The more general modifyi supplies f with the index of the
corresponding element in the slice. The expression modify f sl is
equivalent to modifyi (f o #2) sl.
These functions fold the function f over the
elements of a slice, using the value init as the initial value. The
functions foldli and foldl apply the function f from left to right
(increasing indices), while the functions foldri and foldr work from
right to left (decreasing indices). The more general functions foldli
and foldri supply f with the index of the corresponding element in the
slice. See the MONO_ARRAY manual pages for reference implementations
of the indexed versions. The expression foldl f init sl is equivalent
to (foldli (fn (_, a, x) => f(a, x)) init sl). The analogous
equivalence holds for foldri and foldr.
These functions apply f to each element of the slice sl,
in order of increasing indices, until a true value is returned. If
this occurs, the functions return the element; otherwise, they return
NONE. The more general version findi also supplies f with the index of
the element in the slice and, upon finding an entry satisfying the
predicate, returns that index with the element.
applies f to each element x of the slice sl, in order of
increasing indices, until f x evaluates to true; it returns true if
such an x exists and false otherwise.
applies f to each element x of the slice sl, from left to
right (i.e., increasing indices), until f x evaluates to false; it
returns false if such an x exists and true otherwise. It is equivalent
to not(exists (not o f) l)).