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/branches/idlbasis-devel/src/system/Basis/Implementation/word8-array-slice.sml
ViewVC logotype

Diff of /sml/branches/idlbasis-devel/src/system/Basis/Implementation/word8-array-slice.sml

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

revision 865, Sat Jun 30 03:40:12 2001 UTC revision 866, Mon Jul 2 16:33:10 2001 UTC
# Line 9  Line 9 
9    
10    structure A = InlineT.Word8Array    structure A = InlineT.Word8Array
11    type elem = Word8.word    type elem = Word8.word
12    type array = Wor8Array.array    type array = Word8Array.array
13    type vector = Word8Vector.vector    type vector = Word8Vector.vector
14    type vector_slice = Word8VectorSlice.slice    type vector_slice = Word8VectorSlice.slice
15    datatype slice = SL of {base: array, start: int, stop: int}    datatype slice = SL of {base: array, start: int, stop: int}
# Line 18  Line 18 
18    val (op >=) = InlineT.DfltInt.>=    val (op >=) = InlineT.DfltInt.>=
19    val (op +)  = InlineT.DfltInt.+    val (op +)  = InlineT.DfltInt.+
20    val sub' = A.sub    val sub' = A.sub
21      val update' = A.update
22    val geu = InlineT.DfltInt.geu    val geu = InlineT.DfltInt.geu
23    
24  (* val full : array -> slice *)  (* val full : array -> slice *)
# Line 57  Line 58 
58        end        end
59    
60  (* val update : slice * int * elem -> unit *)  (* val update : slice * int * elem -> unit *)
61  >>>>>    fun update (SL{base,start,stop},j,x) =
62          let val j' = start + j
63          in if geu (j', stop) then raise Core.Subscript
64             else update' (base, j', x)
65          end
66    
67  (* val full : vector -> slice *)  (* val full : array -> slice *)
68    fun full base = SL{base=base,start=0,stop=InlineT.PolyVector.length base}    fun full base = SL{base=base,start=0,stop=A.length base}
69    (*
70        let val blen = V.length base        let val blen = V.length base
71         in if geu(start, blen)  (* checks start >= 0 *)         in if geu(start, blen)  (* checks start >= 0 *)
72            then raise Core.Subscript            then raise Core.Subscript
# Line 71  Line 77 
77                        then raise Core.Subscript                        then raise Core.Subscript
78                        else SL{base=base,start=start,stop=start+n}                        else SL{base=base,start=start,stop=start+n}
79        end        end
80    *)
81    
82  (* val slice : vector * int * int option -> slice *)  (* val slice : vector * int * int option -> slice *)
83    fun slice (base,start,lenOp) =    fun slice (base,start,lenOp) =
84        let val blen = V.length base        let val blen = A.length base
85         in if geu(start, blen)  (* checks start >= 0 *)         in if geu(start, blen)  (* checks start >= 0 *)
86            then raise Core.Subscript            then raise Core.Subscript
87            else case lenOp            else case lenOp
# Line 97  Line 103 
103                       then raise Core.Subscript                       then raise Core.Subscript
104                   else SL{base=base,start=start+i,stop=start+i+n}                   else SL{base=base,start=start+i,stop=start+i+n}
105    
106    (*
107  (* val base : slice -> vector * int * int *)  (* val base : slice -> vector * int * int *)
108    fun full base = SL{base=base,start=0,stop=V.length base}    fun full base = SL{base=base,start=0,stop=V.length base}
109        let val blen = V.length base        let val blen = A.length base
110         in if geu(start, blen)  (* checks start >= 0 *)         in if geu(start, blen)  (* checks start >= 0 *)
111            then raise Core.Subscript            then raise Core.Subscript
112            else case lenOp            else case lenOp
# Line 109  Line 116 
116                        then raise Core.Subscript                        then raise Core.Subscript
117                        else SL{base=base,start=start,stop=start+n}                        else SL{base=base,start=start,stop=start+n}
118        end        end
119    *)
120    
121  (* val vector : slice -> vector *)  (* val vector : slice -> vector *)
122    fun vector (SL{base,start,stop}) =    fun vector (SL{base,start,stop}) =
123        Word8Vector.tabulate((fn n => sub'(base,n+start)),        Word8Vector.tabulate(stop-start, fn n => sub'(base,n+start))
                            stop-start)  
124    
125  (* utility functions *)  (* utility functions *)
126    fun checkLen n =    fun checkLen n =
127        if InlineT.DfltInt.ltu(V.maxLen, n)        if InlineT.DfltInt.ltu(Word8Vector.maxLen, n)
128            then raise General.Size            then raise General.Size
129        else ()        else ()
130    
# Line 151  Line 158 
158  (* val getItem : slice -> (elem * slice) option *)  (* val getItem : slice -> (elem * slice) option *)
159    fun getItem (SL{base,start,stop}) =    fun getItem (SL{base,start,stop}) =
160        if stop<=start then NONE        if stop<=start then NONE
161        else SOME(sub'(base, j'), SL{base=base,start=start+1,stop=stop})        else SOME(sub'(base, start), SL{base=base,start=start+1,stop=stop})
162    
163  (* val appi : (int * elem -> unit) -> slice -> unit *)  (* val appi : (int * elem -> unit) -> slice -> unit *)
164    fun appi f (SL{base,start,stop}) =    fun appi f (SL{base,start,stop}) =
# Line 162  Line 169 
169        end        end
170    
171  (* val app  : (elem -> unit) -> slice -> unit *)  (* val app  : (elem -> unit) -> slice -> unit *)
172    fun appi f (SL{base,start,stop}) =    fun app f (SL{base,start,stop}) =
173        let fun app i = if (i < stop)        let fun app i = if (i < stop)
174                then (f (sub'(base, i)); app(i+1))                then (f (sub'(base, i)); app(i+1))
175                else ()                else ()
# Line 209  Line 216 
216        end        end
217    
218  (* val foldl  : (elem * 'b -> 'b) -> 'b -> slice -> 'b *)  (* val foldl  : (elem * 'b -> 'b) -> 'b -> slice -> 'b *)
219    fun foldli f init (SL{base,start,stop}) =    fun foldl f init (SL{base,start,stop}) =
220        let fun fold (i, accum) = if (i < stop)        let fun fold (i, accum) = if (i < stop)
221                then fold (i+1, f (sub'(base, i), accum))                then fold (i+1, f (sub'(base, i), accum))
222                else accum                else accum
# Line 244  Line 251 
251                then let val item = sub'(base, i)                then let val item = sub'(base, i)
252                      in if f item                      in if f item
253                         then SOME(item)                         then SOME(item)
254                         else findi' (i+1)                         else find' (i+1)
255                     end                     end
256                else NONE                else NONE
257         in find' start         in find' start
# Line 286  Line 293 
293         in cmp(start,start')         in cmp(start,start')
294        end        end
295    
296      fun base (SL{base=b,start,stop}) = (b, start, stop - start)
297    
298      fun copy {src = SL{base,start,stop},dst,di} =
299          if di < 0 orelse
300             di + (stop - start) > A.length dst
301          then raise Core.Subscript
302          else if di <= start
303          then let fun cp i =
304                       if (i < stop)
305                       then (update'(dst,di+i,sub'(base, i));
306                             cp(i+1))
307                       else ()
308                in cp start
309               end
310          else let fun cp i =
311                       if (i >= start)
312                       then (update'(dst,di+i,sub'(base, i));
313                             cp(i-1))
314                       else ()
315                in cp (stop-1)
316               end
317    
318      fun copyVec {src,dst,di} =
319          if di < 0 orelse
320             di + Word8VectorSlice.length src > A.length dst
321          then raise Core.Subscript
322          else Word8VectorSlice.appi(fn (i,x) => update'(dst,di+i,x)) src
323    
324      fun modifyi f (sl as SL{base,start,stop}) =
325          appi (fn (i, x) => update' (base, start+i, f (i, x))) sl
326    
327      fun modify f (sl as SL{base,start,stop}) =
328          appi (fn (i, x) => update' (base, start+i, f x)) sl
329  end (* structure Word8ArraySlice *)  end (* structure Word8ArraySlice *)

Legend:
Removed from v.865  
changed lines
  Added in v.866

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