1 (* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
10 val unsafeSub: 'a t * int -> 'a
11 val unsafeUpdate: 'a t * int * 'a -> unit
18 structure V = Vector (S)
25 fun modify (a, f) = foreachi (a, fn (i, x) => unsafeUpdate (a, i, f x))
28 let val t = sub (a, i)
29 in unsafeUpdate (a, i, sub (a, j))
30 ; unsafeUpdate (a, j, t)
37 Int.for (0, n, fn i => swap (a, i, i + Random.natLessThan (m - i)))
40 fun shuffle a = shuffleN (a, length a)
42 fun getAndSet a = (fn i => sub (a, i),
43 fn (i, x) => update (a, i, x))
51 val a = new (n + 1, x)
55 | x :: l => (unsafeUpdate (a, i, x)
57 val _ = loop (l, n - 1)
61 fun toVectorMap (a, f) = Vector.tabulate (length a, fn i => f (sub (a, i)))
63 fun toVector a = toVectorMap (a, fn x => x)
65 fun fromVector v = tabulate (Vector.length v, fn i => Vector.sub (v, i))