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

SCM Repository

[smlnj] View of /sml/trunk/src/comp-lib/dynamic.sml
ViewVC logotype

View of /sml/trunk/src/comp-lib/dynamic.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 224 - (download) (annotate)
Sat Apr 17 16:27:01 1999 UTC (20 years, 10 months ago) by monnier
File size: 1178 byte(s)
This commit was generated by cvs2svn to compensate for changes in r223,
which included commits to RCS files with non-trunk default branches.
(* Copyright 1989 by AT&T Bell Laboratories *)

signature DYNAMIC_ARRAY = sig type array 
			      exception Subscript 
			      type elem 
			      val array : elem -> array
			      val sub : array * int -> elem
			      val update : (array * int * elem) -> unit
			  end

functor Dynamic( A : MONO_ARRAY ) : DYNAMIC_ARRAY =
  struct
     type array = {default: A.elem, arr: A.array ref}
     type elem = A.elem
     exception Subscript
     infix 9 sub
     fun array e = {default=e, arr= ref(A.array(0,e))};
     fun {default, arr as ref a} sub i = 
	A.sub(a,i)
	handle General.Subscript =>
	    if i < 0 then raise Subscript
	    else default
     fun update ({default,arr as ref a}, i, e) =
       A.update(a,i,e)
       handle General.Subscript =>
       if i<0 then raise Subscript
       else
       let val size = A.length a
	   val newsize = i + size + 1
	   val a2 = A.array(newsize, default)
	   fun copy j = (A.update(a2,j,A.sub(a,j)); copy(j-1))
       in (copy (size - 1) handle General.Subscript => ());
	  arr := a2;
	  A.update(a2,i,e)			
       end

end



(*
 * $Log: dynamic.sml,v $
 * Revision 1.1.1.1  1998/04/08 18:39:14  george
 * Version 110.5
 *
 *)

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