Re: List processing
- To: mathgroup at smc.vnet.net
- Subject: [mg37244] Re: [mg37196] List processing
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Fri, 18 Oct 2002 05:17:15 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Here is a version which compresses the list going forward, it does not
seem to be significantly faster than the other version but the memory
use should be slightly smaller:
(*Handle some degenerate cases here *)
fcompress[{}]:={};
(*This pattern is the stopping point of the recursion*)
fcompress[lst:{{_?NumericQ,_?NumericQ}}]:=lst
(*This function needs to be called with a sorted list*)
fcompress[lst:{{_?NumericQ,_?NumericQ}..}]:=With[{rng1=lst[[1]],rng2=lst
[[2]]},If[rng1[[2]]<rng2[[1]],{rng1,Sequence@@fcompress[Rest[lst]]},fcom
press[Join[{{rng1[[1]],Max[{rng1[[2]],rng2[[2]]}]}},Drop[lst,2]]]]]
Regards,
Sseziwa