[MLton-commit] r5385

Vesa Karvonen vesak at mlton.org
Fri Mar 2 09:56:26 PST 2007


Added isEmpty, fold, and toList.
----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sig
U   mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sml

----------------------------------------------------------------------

Modified: mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sig
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sig	2007-03-02 11:57:10 UTC (rev 5384)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sig	2007-03-02 17:56:21 UTC (rev 5385)
@@ -28,6 +28,9 @@
    val size : 'a t -> Int.t
    (** Returns the number of associations stored in the word table. *)
 
+   val isEmpty : 'a t UnPr.t
+   (** {isEmpty t == 0 = size t} *)
+
    (**
     * The {Action} substructure specifies type-safe combinators for
     * expressing actions to take on access.  In particular, the
@@ -52,4 +55,13 @@
 
    val access : 'v t -> Key.t -> ('v, 'r) Action.t -> 'r
    (** Performs an action on an association of the word table. *)
+
+   val fold : ('v * 's -> 's) -> 's -> 'v t -> 's
+   (**
+    * Fold over all the values stored in the table.  The order in which
+    * the elements are processed is not specified.
+    *)
+
+   val toList : 'a t -> 'a List.t
+   (** Return a list of all values in the table. *)
 end

Modified: mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sml
===================================================================
--- mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sml	2007-03-02 11:57:10 UTC (rev 5384)
+++ mltonlib/trunk/com/ssh/misc-util/unstable/word-table.sml	2007-03-02 17:56:21 UTC (rev 5385)
@@ -29,7 +29,7 @@
 
    fun table (IN {table, ...}) = !table
    fun size (IN {size, ...}) = !size
-
+   fun isEmpty t = 0 = size t
    fun keyToIdx t key = W.toIntX (key mod W.fromInt (V.length (table t)))
    fun putAt t idx entry = N.push (V.sub (table t, idx)) entry
    fun newTable cap = V.tabulate (cap, N.ptr o ignore)
@@ -110,4 +110,9 @@
 
    fun access t key action =
        action (findKey t (keyToIdx t key) key, key, t)
+
+   fun fold f s =
+       Vector.foldl (fn (l, s) => N.fold (f o Pair.map (#2, id)) s l) s o table
+
+   fun toList t = fold op :: [] t
 end




More information about the MLton-commit mailing list