alice
library
manual.

Alice Project

The Array structure


________ Synopsis ____________________________________________________

    signature ARRAY
    structure Array : ARRAY
  

An extended version of the Standard ML Basis' Array structure.

See also: Array2, ArraySlice, MONO_ARRAY, Vector


________ Import ______________________________________________________

Imported implicitly.


________ Interface ___________________________________________________

    signature ARRAY =
    sig
	eqtype 'a array
	type 'a vector
	type 'a t = 'a array

	val maxLen :      int

	val array :       int * 'a -> 'a array
	val vector :      'a array -> 'a vector
	val fromList :    'a list -> 'a array
	val toList :      'a array -> 'a list
	val fromVector :  'a vector -> 'a array
	val toVector :    'a array -> 'a vector
	val tabulate :    int * (int -> 'a) -> 'a array

	val length :      'a array -> int
	val sub :         'a array * int -> 'a
	val update :      'a array * int * 'a -> unit
	val swap :        'a array * int * int -> unit
	val rev :         'a array -> unit
	val copy :        {src : 'a array,  dst : 'a array, di : int} -> unit
	val copyVec :     {src : 'a vector, dst : 'a array, di : int} -> unit

	val app :         ('a -> unit) -> 'a array -> unit
	val appr :        ('a -> unit) -> 'a array -> unit
	val modify :      ('a -> 'a) -> 'a array -> unit
	val foldl :       ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
	val foldr :       ('a * 'b -> 'b) -> 'b -> 'a array -> 'b
	val all :         ('a -> bool) -> 'a array -> bool
	val exists :      ('a -> bool) -> 'a array -> bool
	val find :        ('a -> bool) -> 'a array -> 'a option

	val appi :        (int * 'a -> unit) -> 'a array -> unit
	val appri :       (int * 'a -> unit) -> 'a array -> unit
	val modifyi :     (int * '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 alli :        (int * 'a -> bool) -> 'a array -> bool
	val existsi :     (int * 'a -> bool) -> 'a array -> bool
	val findi :       (int * 'a -> bool) -> 'a array -> (int * 'a) option

	val contains :    ''a array -> ''a -> bool
	val notContains : ''a array -> ''a -> bool

	val equal :       ('a * 'a -> bool) -> 'a array * 'a array -> bool
	val collate :     ('a * 'a -> order) -> 'a array * 'a array -> order

	val isSorted :    ('a * 'a -> order) -> 'a array -> bool
	val sort :        ('a * 'a -> order) -> 'a array -> unit
    end
  

________ Description _________________________________________________

Items not described here are as in the Standard ML Basis' Array structure.

type t = array

A local synonym for type array.

fromVector v

Creates a vector containing the same elements as the array arr. If v contains more than maxLen elements, then the Size exception is raised.

toVector arr

Creates a vector containing the same elements as the array arr. If arr contains more than Vector.maxLen elements, then the Size exception is raised. Equivalent to vector arr.

toList arr

Creates a list of the elements of arr in order of increasing indices.

rev arr

Reverses in-place the order of elements in array arr.

swap (arr, i, j)

Swaps the ith and jth element of array arr. If i < 0 or |arr| <= i, or j < 0 or |arr| <= j, then the Subscript exception is raised.

appr f arr
appri f arr

Like appi and app, but apply f in right to left order (i.e., decreasing indices). The expression app f arr is equivalent to:

        appri (f o #2) arr
alli f arr
existsi f arr

Indexed versions of the functions all and exists. The index of each element is passed to f as an additional argument. The following equivalences hold:

        all f arr    = alli (f o #2) arr
        exists f arr = existsi (f o #2) arr
contains arr a

Returns true if the element a occurs in the array arr; otherwise false.

notContains arr a

Returns true if the element a does not occur in the array arr; otherwise false. Equivalent to not(contains arr a).

equal eq (arr1, arr2)

Creates an equality function on arrays given an equality on the element type.

isSorted f arr

Returns true iff arr is sorted with respect to the ordering function f.

sort f arr

Sorts arr with respect to the ordering function f. Sorting may be unstable with respect to equal elements.



last modified 2007/Mar/30 17:10