Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Tracker SCM

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/library/hash-array.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/library/hash-array.sml

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

revision 1349, Wed Sep 3 22:22:18 2003 UTC revision 1350, Fri Sep 5 21:34:27 2003 UTC
# Line 24  Line 24 
24    
25      val maxLen   = A.maxLen      val maxLen   = A.maxLen
26    
     exception HashArrayUnimplemented  
   
     fun unimplemented _ = raise HashArrayUnimplemented  
   
27      fun array(n,d) = ARRAY(ref(A.array(16,[])),V d,ref n,ref 0)      fun array(n,d) = ARRAY(ref(A.array(16,[])),V d,ref n,ref 0)
28      fun array'(n,f) = ARRAY(ref(A.array(16,[])),F f,ref n,ref 0)      fun array'(n,f) = ARRAY(ref(A.array(16,[])),F f,ref n,ref 0)
29      fun array''(n,f) = ARRAY(ref(A.array(16,[])),U f,ref n,ref 0)      fun array''(n,f) = ARRAY(ref(A.array(16,[])),U f,ref n,ref 0)
# Line 39  Line 35 
35    
36      fun copy_array(ARRAY(ref a,d,ref n,ref c)) =      fun copy_array(ARRAY(ref a,d,ref n,ref c)) =
37           let val a' = A.array(n,[])           let val a' = A.array(n,[])
38               val _  = A.copy{src=a,dst=a',si=0,di=0,len=NONE}               val _  = A.copy{src=a,dst=a',di=0}
39           in  ARRAY(ref a',d,ref n,ref c)           in  ARRAY(ref a',d,ref n,ref c)
40           end           end
41    
# Line 129  Line 125 
125      in  change(A.sub(a,pos),[])      in  change(A.sub(a,pos),[])
126      end      end
127    
128      fun extract (a as ARRAY(_,_,ref n,_),i,j) =      (* These seem bogus since they do not run in order *)
129      let val j = case j of SOME j => i+j | NONE => n      fun appi f (ARRAY(ref a,_,ref n,_)) = A.app (List.app f) a
130          fun f(k,l) = if k < i then l else f(k-1,sub(a,k)::l)      fun app f (ARRAY(ref a,_,_,_)) = A.app (List.app (fn (_,x) => f x)) a
     in  
         Vector.fromList(f(j-1,[]))  
     end  
131    
132      fun copy { src = src as ARRAY(_,_,ref n,_), si, len, dst, di } =      fun copy { src, dst, di } =
133      let val j = case len of SOME len => si+len | NONE => n          appi (fn (i, x) => update (dst, i, x)) src
         fun f(k,k') = if k >= j then ()  
                       else (update(dst,k',sub(src,k)); f(k+1,k'+1))  
     in  f(si,di)  
     end  
134    
135      val copyVec = unimplemented      fun copyVec { src, dst, di } =
136            Vector.appi (fn (i, x) => update (dst, di + i, x)) src
137    
138        (* These seem bogus since they do not run in order *)
139        fun foldli f e (ARRAY(ref a,_,_,_)) =
140            A.foldl (fn (l, e) => List.foldl (fn ((i,x),e) => f (i,x,e)) e l) e a
141        fun foldri f e (ARRAY(ref a,_,_,_)) =
142            A.foldr (fn (l, e) => List.foldr (fn ((i,x),e) => f (i,x,e)) e l) e a
143    
     fun app f (ARRAY(ref a,_,_,_)) = A.app (List.app (fn (_,x) => f x)) a  
144      fun foldl f e (ARRAY(ref a,_,_,_)) =      fun foldl f e (ARRAY(ref a,_,_,_)) =
145         A.foldl (fn (l,e) => List.foldl (fn ((_,x),e) => f(x,e)) e l) e a         A.foldl (fn (l,e) => List.foldl (fn ((_,x),e) => f(x,e)) e l) e a
146      fun foldr f e (ARRAY(ref a,_,_,_)) =      fun foldr f e (ARRAY(ref a,_,_,_)) =
147         A.foldr (fn (l,e) => List.foldr (fn ((_,x),e) => f(x,e)) e l) e a         A.foldr (fn (l,e) => List.foldr (fn ((_,x),e) => f(x,e)) e l) e a
148    
149        fun modifyi f (ARRAY(ref a,_,_,_)) =
150            A.modify (List.map (fn (i,x) => (i, f (i, x)))) a
151    
152      fun modify f (ARRAY(ref a,_,_,_)) =      fun modify f (ARRAY(ref a,_,_,_)) =
153         A.modify (List.map (fn (i,x) => (i,f x))) a         A.modify (List.map (fn (i,x) => (i,f x))) a
154    
     fun appi f (ARRAY(ref a,_,ref n,_),i,j) =  
     let val j = case j of SOME j => i+j | NONE => n  
     in  A.app (List.app  
            (fn (k,x) => if k >= i andalso k < j then f(k,x) else ())) a  
     end  
     fun foldli f e (ARRAY(ref a,_,ref n,_),i,j) =  
     let val j = case j of SOME j => i+j | NONE => n  
     in  A.foldl (fn (l,e) => List.foldl  
            (fn ((k,x),e) => if k >= i andalso k < j then f(k,x,e) else e) e l)  
            e a  
     end  
     fun foldri f e (ARRAY(ref a,_,ref n,_),i,j) =  
     let val j = case j of SOME j => i+j | NONE => n  
     in  A.foldr (fn (l,e) => List.foldr  
            (fn ((k,x),e) => if k >= i andalso k < j then f(k,x,e) else e) e l)  
            e a  
     end  
155      fun dom(ARRAY(ref a,_,_,_)) =      fun dom(ARRAY(ref a,_,_,_)) =
156         A.foldl (fn (e,l) => List.foldr (fn ((i,_),l) => i::l) l e) [] a         A.foldl (fn (e,l) => List.foldr (fn ((i,_),l) => i::l) l e) [] a
157    
158      fun modifyi f (ARRAY(ref a,_,ref n,_),i,j) =      fun findi p (ARRAY(ref a,_,_,_)) = let
159      let val j = case j of SOME j => i+j | NONE => n          val len = A.length a
160      in  A.modify (List.map(fn (k,x) => if k >= i andalso k < j then (k,f(k,x))          fun fnd i =
161                                         else (k,x))) a              if i >= len then NONE
162                else case List.find p (A.sub (a, i)) of
163                         NONE => fnd (i + 1)
164                       | some => some
165        in
166            fnd 0
167      end      end
168    
169        fun find p (ARRAY(ref a,_,_,_)) = let
170            val len = A.length a
171            fun fnd i =
172                if i >= len then NONE
173                else case List.find (p o #2) (A.sub (a, i)) of
174                         NONE => fnd (i + 1)
175                       | SOME (_, x) => SOME x
176        in
177            fnd 0
178  end  end
179    
180        fun exists p arr = isSome (find p arr)
181        fun all p arr = not (isSome (find (not o p) arr))
182        fun collate _ _ = raise Fail "HashArray.collate unimplemented"
183    
184        fun vector arr = Vector.fromList (rev (foldl op :: [] arr))
185    end

Legend:
Removed from v.1349  
changed lines
  Added in v.1350

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