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/MLRISC/library/dynamic-array.sml
ViewVC logotype

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

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

revision 470, Wed Nov 10 22:42:52 1999 UTC revision 624, Fri Apr 21 03:06:21 2000 UTC
# Line 6  Line 6 
6    
7  structure DynArray :  structure DynArray :
8    sig include ARRAY    sig include ARRAY
9          val fromArray : 'a Array.array * 'a * int -> 'a array
10        val baseArray : 'a array -> 'a Array.array        val baseArray : 'a array -> 'a Array.array
11        val checkArray: 'a array * 'a Array.array -> unit        val checkArray: 'a array * 'a Array.array -> unit
12        val clear     : 'a array * int -> unit        val clear     : 'a array * int -> unit
13          val expandTo  : 'a array * int -> unit
14    end =    end =
15    struct    struct
16       structure A = Array       structure A = Array
# Line 25  Line 27 
27    
28       fun array (n,d) = ARRAY(ref(A.array (n,d)), d, ref 0)       fun array (n,d) = ARRAY(ref(A.array (n,d)), d, ref 0)
29       fun clear (ARRAY(a,def,cnt),n) = (a := A.array(n,def); cnt := n)       fun clear (ARRAY(a,def,cnt),n) = (a := A.array(n,def); cnt := n)
30         fun fromArray(a,d,n) = ARRAY(ref a, d, ref n)
31    
32       fun baseArray(ARRAY(ref a,_,_)) = a       fun baseArray(ARRAY(ref a,_,_)) = a
33       fun checkArray(ARRAY(ref a,_,_),a') = if a = a' then () else raise Match       fun checkArray(ARRAY(ref a,_,_),a') = if a = a' then () else raise Match
# Line 34  Line 37 
37       fun (ARRAY(ref a, d, _)) sub i = A.sub(a,i) handle _ => d       fun (ARRAY(ref a, d, _)) sub i = A.sub(a,i) handle _ => d
38    
39       fun update (ARRAY(r as ref a, d, n), i, e) =       fun update (ARRAY(r as ref a, d, n), i, e) =
40          (A.update(a,i,e); n := Int.max(!n,i+1)) handle Subscript =>          (A.update(a,i,e); n := Int.max(!n,i+1)) handle _ =>
41              let val new_size  = Int.max(i+1,!n*2)              let val new_size  = Int.max(i+1,!n*2)
42                  val new_size  = if new_size < 10 then 10 else new_size                  val new_size  = if new_size < 10 then 10 else new_size
43                  val new_array = A.array(new_size,d)                  val new_array = A.array(new_size,d)
# Line 44  Line 47 
47                  A.update(new_array, i, e)                  A.update(new_array, i, e)
48              end              end
49    
50         fun expandTo(arr as ARRAY(_, d, _), N) = update(arr, N-1, d)
51    
52       fun extract (ARRAY(r as ref a, _, ref n), i, j) = A.extract (a, i, j)       fun extract (ARRAY(r as ref a, _, ref n), i, j) = A.extract (a, i, j)
53    
54       fun copy { src = ARRAY(ref a,_,sz), si, len, dst, di } =       fun copy { src = ARRAY(ref a,_,sz), si, len, dst, di } =
# Line 62  Line 67 
67               val default = A.sub(array,0)               val default = A.sub(array,0)
68           in           in
69               ARRAY(ref array, default, ref n)               ARRAY(ref array, default, ref n)
70           end handle Subscript => raise Size           end handle _ => raise Size
71    
72       fun fromList l =       fun fromList l =
73           let val array   = A.fromList l           let val array   = A.fromList l
74               val default = A.sub(array,0)               val default = A.sub(array,0)
75           in           in
76               ARRAY(ref array, default, ref (List.length l))               ARRAY(ref array, default, ref (List.length l))
77           end handle Subscript => raise Size           end handle _ => raise Size
78    
79       fun app f (ARRAY (ref a,_,ref n)) =       fun app f (ARRAY (ref a,_,ref n)) =
80           A.appi (fn (_,x) => f x) (a,0,SOME n)           A.appi (fn (_,x) => f x) (a,0,SOME n)

Legend:
Removed from v.470  
changed lines
  Added in v.624

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