MathGroup Archive 1992

[Date Index] [Thread Index] [Author Index]

Search the Archive

maybe better union of intervals


(* Take a list of intervals of the form {{low1, high1} ...{lown,highn}}
   and return a list of maximal intervals, sorted by lower endpoints *)

 (*an empty list is a list of maximal intervals. *)

mi[{}]:={}

 (* a list of one interval is also *)

mi[a:{_}]:=a 

 (* given an interval a ={low,hi} and a list L of maximal intervals,
sorted, with  the lowest (first) element of L = {l,h}, and with
low <= l, then a new list L' of maximal intervals consists either of
appending a to L, or merging a with {l,h}, and appending that to the
rest of L. The merge is necessary exactly when hi >=l *)

mi[list:{a_,__}]:=mi1[a,mi[Rest[list]]]

mi1[a_,Null]:={a}
mi1[new:{low_,hi_},old:{{l_,h_},___} ]:=
         If [hi>=l, 
                Prepend[Rest[old],{Min[l,low],Max[hi,h]}],
            	Prepend[old,new]]
		
UnionOfListOfIntervals[a_]:=mi[Sort[a]]





  • Prev by Date: Re: Mie scattering
  • Next by Date: Re: Functional solution to union of intervals
  • Previous by thread: Quaternions etc.
  • Next by thread: Re: Polygons