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 /smlnj-lib/branches/rt-transition/Util/dynamic-array.sml
ViewVC logotype

Diff of /smlnj-lib/branches/rt-transition/Util/dynamic-array.sml

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

revision 4069, Tue Jun 9 20:52:48 2015 UTC revision 4070, Thu Jun 11 12:33:25 2015 UTC
# Line 11  Line 11 
11    
12      structure A = Array      structure A = Array
13    
14      (* BLOCK(arr, dflt, bnd):
15       *    arr     - current data store; is at least !bnd+1 elements
16       *    dflt    - default value
17       *    bnd     - values at !bnd and above are default for reading
18       *)
19      datatype 'a array = BLOCK of ('a A.array ref * 'a * int ref)      datatype 'a array = BLOCK of ('a A.array ref * 'a * int ref)
20    
21      exception Subscript = General.Subscript      exception Subscript = General.Subscript
# Line 20  Line 25 
25    
26    (* fromList (l, v) creates an array using the list of values l    (* fromList (l, v) creates an array using the list of values l
27     * plus the default value v.     * plus the default value v.
    * NOTE: Once MONO_ARRAY includes arrayoflist, this will become trivial.  
28     *)     *)
29      fun fromList (initList, dflt) = let      fun fromList (initList, dflt) = let
30            val len = length initList            val arr = A.fromList initList
           val arr = A.array(len, dflt)  
           fun upd ([], _) = ()  
             | upd (x::r, i) = (A.update(arr, i, x); upd(r, i+1))  
31            in            in
32              upd (initList, 0);              BLOCK(ref arr, dflt, ref(A.length arr - 1))
             BLOCK(ref arr, dflt, ref (len-1))  
33            end            end
34    
35    (* tabulate (sz,fill,dflt) acts like Array.tabulate, plus    (* tabulate (sz,fill,dflt) acts like Array.tabulate, plus
# Line 95  Line 95 
95    
96    (* get the array slice that covers the defined portion of the array *)    (* get the array slice that covers the defined portion of the array *)
97      fun slice (BLOCK(arr, _, bnd)) =      fun slice (BLOCK(arr, _, bnd)) =
98            ArraySlice.slice(!arr, 0, SOME(!bnd))            ArraySlice.slice(!arr, 0, SOME(!bnd + 1))
99    
100    (* we implement the iterators by using the array slice operations *)    (* we implement the iterators by using the array slice operations *)
101      fun vector arr = ArraySlice.vector (slice arr)      fun vector arr = ArraySlice.vector (slice arr)

Legend:
Removed from v.4069  
changed lines
  Added in v.4070

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