CVS: sml/src/smlnj-lib/Util interval-set-fn.sml,1.2,1.3 interval-set-sig.sml,1.1,1.2

John Reppy <[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj.commits
Message-ID <[email protected]>
Update of /cvsroot/smlnj/sml/src/smlnj-lib/Util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5858/util

Modified Files:
	interval-set-fn.sml interval-set-sig.sml 
Log Message:
  Tweaking of the interval set API; see CHANGES file for details.


Index: interval-set-fn.sml
===================================================================
RCS file: /cvsroot/smlnj/sml/src/smlnj-lib/Util/interval-set-fn.sml,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** interval-set-fn.sml	31 Oct 2005 16:47:44 -0000	1.2
--- interval-set-fn.sml	5 Nov 2005 15:34:45 -0000	1.3
***************
*** 42,46 ****
  	  (* end case *))
  
!     fun addInterval (SET l, (a, b)) = let
  	  fun ins (a, b, []) = [(a, b)]
  	    | ins (a, b, (x, y)::r) = (case D.compare(b, x)
--- 42,46 ----
  	  (* end case *))
  
!     fun addInt (SET l, (a, b)) = let
  	  fun ins (a, b, []) = [(a, b)]
  	    | ins (a, b, (x, y)::r) = (case D.compare(b, x)
***************
*** 66,70 ****
  	    (* end case *)
  	  end
!     fun addInterval' (x, m) = addInterval (m, x)
  
      fun add (SET l, a) = let
--- 66,70 ----
  	    (* end case *)
  	  end
!     fun addInt' (x, m) = addInt (m, x)
  
      fun add (SET l, a) = let
***************
*** 200,212 ****
      fun difference (s1, s2) = intersect(s1, complement s2)
  
!     fun list (SET l) = l
  
!     fun app f (SET l) = List.app f l
  
!     fun foldl f init (SET l) = List.foldl f init l
  
!     fun foldr f init (SET l) = List.foldl f init l
  
!     fun filter pred (SET l) = let
  	  fun f' ([], l) = SET(List.rev l)
  	    | f' (i::r, l) = if pred i
--- 200,299 ----
      fun difference (s1, s2) = intersect(s1, complement s2)
  
!   (***** iterators on elements *****)
!     local
!       fun next [] = NONE
! 	| next ((a, b)::r) =
! 	    if D.compare(a, b) = EQUAL
! 	      then SOME(a, r)
! 	      else SOME(a, (D.succ a, b)::r)
!     in
!     fun items (SET l) = let
! 	  fun list (l, items) = (case next l
! 		 of NONE => List.rev items
! 		  | SOME(x, r) => list(r, x::items)
! 		(* end case *))
! 	  in
! 	    list (l, [])
! 	  end
!     fun app f (SET l) = let
! 	  fun appf l = (case next l
! 		 of NONE => ()
! 		  | SOME(x, r) => (f x; appf r)
! 		(* end case *))
! 	  in
! 	    appf l
! 	  end
!     fun foldl f = let
! 	  fun foldf (l, acc) = (case next l
! 		 of NONE => acc
! 		  | SOME(x, r) => foldf(r, f(x, acc))
! 		(* end case *))
! 	  in
! 	    fn init => fn (SET l) => foldf(l, init)
! 	  end
!     fun foldr f init (SET l) = let
! 	  fun foldf l = (case next l
! 		 of NONE => init
! 		  | SOME(x, r) => f (x, foldf r)
! 		(* end case *))
! 	  in
! 	    foldf l
! 	  end
!     fun filter pred (SET l) = let
! 	(* given an interval [a, b], filter its elements and add the subintervals that pass
! 	 * the predicate to the list l.
! 	 *)
! 	  fun filterInt ((a, b), l) = let
! 		fun lp (start, item, last, l) = let
! 		      val next = D.succ item
! 		      in
! 			if pred next
! 			  then if (D.compare(next, last) = EQUAL)
! 			    then (start, next)::l
! 			    else lp(start, next, last, l)
! 			  else scan(D.succ next, last, (start, item)::l)
! 		      end
! 		and scan (next, last, l) = if pred next
! 		      then lp (next, next, last, l)
! 		      else if (D.compare(next, last) = EQUAL)
! 			then l
! 			else scan(D.succ next, last, l)
! 		in
! 		  scan (a, b, l)
! 		end
! 	(* filter the intervals *)
! 	  fun filter' ([], l) = SET(List.rev l)
! 	    | filter' (i::r, l) = filter' (r, filterInt (i, l))
! 	  in
! 	    filter' (l, [])
! 	  end
!     fun all pred (SET l) = let
! 	  fun all' l = (case next l
! 		 of NONE => true
! 		  | SOME(x, r) => (pred x andalso all' r)
! 		(* end case *))
! 	  in
! 	    all' l
! 	  end
!     fun exists pred (SET l) = let
! 	  fun exists' l = (case next l
! 		 of NONE => false
! 		  | SOME(x, r) => (pred x orelse exists' r)
! 		(* end case *))
! 	  in
! 	    exists' l
! 	  end
!     end (* local *)
  
!   (***** Iterators on interfuns *****)
!     fun intervals (SET l) = l
  
!     fun appInt f (SET l) = List.app f l
  
!     fun foldlInt f init (SET l) = List.foldl f init l
  
!     fun foldrInt f init (SET l) = List.foldl f init l
! 
!     fun filterInt pred (SET l) = let
  	  fun f' ([], l) = SET(List.rev l)
  	    | f' (i::r, l) = if pred i
***************
*** 217,223 ****
  	  end
  
!     fun exists pred (SET l) = List.exists pred l
  
!     fun all pred (SET l) = List.all pred l
  
      fun compare (SET l1, SET l2) = let
--- 304,310 ----
  	  end
  
!     fun existsInt pred (SET l) = List.exists pred l
  
!     fun allInt pred (SET l) = List.all pred l
  
      fun compare (SET l1, SET l2) = let

Index: interval-set-sig.sml
===================================================================
RCS file: /cvsroot/smlnj/sml/src/smlnj-lib/Util/interval-set-sig.sml,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** interval-set-sig.sml	25 Oct 2005 15:38:51 -0000	1.1
--- interval-set-sig.sml	5 Nov 2005 15:34:45 -0000	1.2
***************
*** 33,38 ****
      val member : set * item -> bool
  
    (* return a list of intervals that represents the set *)
!     val list : set -> interval list
  
    (* add a single element to the set *)
--- 33,41 ----
      val member : set * item -> bool
  
+   (* return the list of items in the set *)
+     val items : set -> item list
+ 
    (* return a list of intervals that represents the set *)
!     val intervals : set -> interval list
  
    (* add a single element to the set *)
***************
*** 41,46 ****
  
    (* add an interval to the set *)
!     val addInterval : set * interval -> set
!     val addInterval' : interval * set -> set
  
    (* set operations *)
--- 44,49 ----
  
    (* add an interval to the set *)
!     val addInt : set * interval -> set
!     val addInt' : interval * set -> set
  
    (* set operations *)
***************
*** 50,60 ****
      val difference : (set * set) -> set
  
!   (* iterators *)
!     val app : (interval -> unit) -> set -> unit
!     val foldl : (interval * 'a -> 'a) -> 'a -> set -> 'a
!     val foldr : (interval * 'a -> 'a) -> 'a -> set -> 'a
!     val filter : (interval -> bool) -> set -> set
!     val all : (interval -> bool) -> set -> bool
!     val exists : (interval -> bool) -> set -> bool
  
    (* ordering on sets *)
--- 53,71 ----
      val difference : (set * set) -> set
  
!   (* iterators on elements *)
!     val app    : (item -> unit) -> set -> unit
!     val foldl  : (item * 'a -> 'a) -> 'a -> set -> 'a
!     val foldr  : (item * 'a -> 'a) -> 'a -> set -> 'a
!     val filter : (item -> bool) -> set -> set
!     val all    : (item -> bool) -> set -> bool
!     val exists : (item -> bool) -> set -> bool
! 
!   (* iterators on intervals *)
!     val appInt    : (interval -> unit) -> set -> unit
!     val foldlInt  : (interval * 'a -> 'a) -> 'a -> set -> 'a
!     val foldrInt  : (interval * 'a -> 'a) -> 'a -> set -> 'a
!     val filterInt : (interval -> bool) -> set -> set
!     val allInt    : (interval -> bool) -> set -> bool
!     val existsInt : (interval -> bool) -> set -> bool
  
    (* ordering on sets *)



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.