Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/comp-lib/intmap.sml
ViewVC logotype

Diff of /sml/trunk/src/comp-lib/intmap.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 418, Fri Sep 3 23:51:27 1999 UTC revision 429, Wed Sep 8 09:47:00 1999 UTC
# Line 8  Line 8 
8    datatype 'a bucket = NIL | B of (int * 'a * 'a bucket)    datatype 'a bucket = NIL | B of (int * 'a * 'a bucket)
9    datatype 'a intmap =    datatype 'a intmap =
10      H of {table: 'a bucket array ref,elems: int ref,exn: exn,name: string option}      H of {table: 'a bucket array ref,elems: int ref,exn: exn,name: string option}
11    fun clear(H{table,elems,...}) = (table := array(32,NIL); elems := 0)    fun clear(H{table,elems,...}) =
12          if !elems > 0 then (table := array(32,NIL); elems := 0) else ()
13    fun bucketapp f =    fun bucketapp f =
14        let fun loop NIL = ()        let fun loop NIL = ()
15              | loop(B(i,j,r)) = (f(i,j); loop r)              | loop(B(i,j,r)) = (f(i,j); loop r)
# Line 30  Line 31 
31                     val ref a = table                     val ref a = table
32                 in find(a sub (index(a, i)))                 in find(a sub (index(a, i)))
33                 end)                 end)
34      fun mapWithDefault (H{table,exn,...},default) =
35          (fn i => let fun find NIL = default
36                         | find(B(i',j,r)) = if i=i' then j else find r
37                       val ref a = table
38                   in find(a sub (index(a, i)))
39                   end)
40      fun mapInt (H{table,exn,...}) =
41          (fn i => let fun find NIL = i
42                         | find(B(i',j,r)) = if i=i' then j else find r
43                       val ref a = table
44                   in find(a sub (index(a, i)))
45                   end)
46    fun rmv (H{table=ref a,elems,...}) i =    fun rmv (H{table=ref a,elems,...}) i =
47        let fun f(B(i',j,r)) = if i=i' then (elems := !elems-1; r) else B(i',j,f r)        let fun f(B(i',j,r)) = if i=i' then (elems := !elems-1; r) else B(i',j,f r)
48              | f x = x              | f x = x
# Line 77  Line 90 
90           |   loop (n, NIL, acc) = loop(n-1, a sub (n-1), acc)           |   loop (n, NIL, acc) = loop(n-1, a sub (n-1), acc)
91        in loop(last,a sub last,[])        in loop(last,a sub last,[])
92       end       end
93      fun values(H{table,...})=
94       let val a = !table;
95             val last = Array.length a - 1
96             fun loop (0, NIL, acc) = acc
97             |   loop (n, B(i,j,r), acc) = loop(n, r, j::acc)
98             |   loop (n, NIL, acc) = loop(n-1, a sub (n-1), acc)
99          in loop(last,a sub last,[])
100         end
101      fun keys(H{table,...})=
102       let val a = !table;
103             val last = Array.length a - 1
104             fun loop (0, NIL, acc) = acc
105             |   loop (n, B(i,j,r), acc) = loop(n, r, i::acc)
106             |   loop (n, NIL, acc) = loop(n-1, a sub (n-1), acc)
107          in loop(last,a sub last,[])
108         end
109    
110      fun copy(H{table=ref a,elems,exn,name}) =
111      let val a' = Array.array(Array.length a,NIL)
112      in  Array.copy{di=0, dst=a', len=NONE, si=0, src=a};
113          H{table=ref a', elems=ref(!elems), exn=exn, name=name}
114      end
115    
116  end  end
117    

Legend:
Removed from v.418  
changed lines
  Added in v.429

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0