Vector
structure
signature VECTOR
structure Vector
:> VECTOR
The Vector
structure defines polymorphic vectors, immutable sequences with constant-time access.
eqtype 'a vector = 'a vector
val maxLen : int
val fromList : 'a list -> 'a vector
val tabulate : int * (int -> 'a) -> 'a vector
val length : 'a vector -> int
val sub : 'a vector * int -> 'a
val update : 'a vector * int * 'a -> 'a vector
val concat : 'a vector list -> 'a vector
val appi : (int * 'a -> unit) -> 'a vector -> unit
val app : ('a -> unit) -> 'a vector -> unit
val mapi : (int * 'a -> 'b) -> 'a vector -> 'b vector
val map : ('a -> 'b) -> 'a vector -> 'b vector
val foldli : (int * 'a * 'b -> 'b) -> 'b -> 'a vector -> 'b
val foldri : (int * 'a * 'b -> 'b) -> 'b -> 'a vector -> 'b
val foldl : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b
val foldr : ('a * 'b -> 'b) -> 'b -> 'a vector -> 'b
val findi : (int * 'a -> bool)
-> 'a vector -> (int * 'a) option
val find : ('a -> bool) -> 'a vector -> 'a option
val exists : ('a -> bool) -> 'a vector -> bool
val all : ('a -> bool) -> 'a vector -> bool
val collate : ('a * 'a -> order)
-> 'a vector * 'a vector -> order
val maxLen : int
Size
exception being raised.
fromList l
length l
and with the i(th) element of l used as the i(th) element of the vector. If the length of the list is greater than maxLen
, then the Size
exception is raised.
tabulate (n, f)
fromList (List.tabulate (n, f))If n < 0 or
maxLen
< n, then the Size
exception is raised.
length vec
sub (vec, i)
Subscript
exception is raised.
update (vec, i, x)
Subscript
exception is raised.
concat l
maxLen
, then the Size
exception is raised.
appi f vec
app f vec
appi
function supplies both the element and the element's index to the function f. These are respectively equivalent to:
List.app f (foldri (fn (i,a,l) => (i,a)::l) [] vec) List.app f (foldr (fn (a,l) => a::l) [] vec)
mapi f vec
map f vec
mapi
supplies f
with the vector index of an element along with the element. These are respectively equivalent to:
fromList (List.map f (foldri (fn (i,a,l) => (i,a)::l) [] vec)) fromList (List.map f (foldr (fn (a,l) => a::l) [] vec))
foldli f init vec
foldri f init vec
foldl f init vec
foldr f init vec
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 both the element and the element's index to the function f.
Refer to the MONO_ARRAY
manual pages for reference implementations of the indexed versions.
The last two expressions are respectively equivalent to:
foldli (fn (_, a, x) => f(a, x)) init vec foldri (fn (_, a, x) => f(a, x)) init vec
findi f vec
find f vec
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 vector index of the element and, upon finding an entry satisfying the predicate, returns that index with the element.
exists f vec
f(x)
evaluates to true
; it returns true
if such an x exists and false
otherwise.
all f vec
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
) vec))
.
collate f (v1, v2)
Array
,MONO_VECTOR
,VectorSlice
Generated April 12, 2004
Last Modified January 21, 1997
Comments to John Reppy.
This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.
Copyright © 2004 AT&T and Lucent Technologies. All rights reserved.
Permission is granted for internet users to make one paper copy for their
own personal use. Further hardcopy reproduction is strictly prohibited.
Permission to distribute the HTML document electronically on any medium
other than the internet must be requested from the copyright holders by
contacting the editors.
Printed versions of the SML Basis Manual are available from Cambridge
University Press.
To order, please visit
www.cup.org (North America) or
www.cup.cam.ac.uk (outside North America). |