Re: Merging overlapping spans/ranges

2005-05-11 Thread Bengt Richter
On Tue, 10 May 2005 23:53:43 GMT, Jim Sizelove <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: [...] >> Maybe (not tested beyond what you see ;-) I had that feeling ... somehow the word "max" was trying to get my attention, but I posted without figuring out why ;-/ > >It is with some trepidation t

Re: Merging overlapping spans/ranges

2005-05-11 Thread Max M
Jim Sizelove wrote: Wow! c.l.py is allmost like an AI program generator. But I guess it helps to ask questions about problems that programmers find interresting :-) The "linear" approach is pretty simple to code and understand. I am just afraid what happens when many users tries to book that 1

Re: Merging overlapping spans/ranges

2005-05-11 Thread Jordan Rastrick
Should work fine as far as I can see. Of course, thats not very 'pythonic' - I should probably give at least 10 different unit tests that it passes ;) Its gratifying to know I'm not the only one who needed that final yield. Jim Sizelove wrote: > Bengt Richter wrote: > > On Tue, 10 May 2005 15:14:

Re: Merging overlapping spans/ranges

2005-05-10 Thread Jim Sizelove
Bengt Richter wrote: > On Tue, 10 May 2005 15:14:47 +0200, Max M <[EMAIL PROTECTED]> wrote: > > >>I am writing a "find-free-time" function for a calendar. There are a lot >>of time spans with start end times, some overlapping, some not. >> >>To find the free time spans, I first need to convert t

Re: Merging overlapping spans/ranges

2005-05-10 Thread Bengt Richter
On Tue, 10 May 2005 15:14:47 +0200, Max M <[EMAIL PROTECTED]> wrote: >I am writing a "find-free-time" function for a calendar. There are a lot >of time spans with start end times, some overlapping, some not. > >To find the free time spans, I first need to convert the events into a >list of non o

Re: Merging overlapping spans/ranges

2005-05-10 Thread Bengt Richter
On Tue, 10 May 2005 15:14:47 +0200, Max M <[EMAIL PROTECTED]> wrote: >I am writing a "find-free-time" function for a calendar. There are a lot >of time spans with start end times, some overlapping, some not. > >To find the free time spans, I first need to convert the events into a >list of non o

Re: Merging overlapping spans/ranges

2005-05-10 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > The linear method: > > You create an array - one bool per minute. For one day 24 * 60 entries > is enough. Spans (Start, End) are in minutes from midnight. Set array > slots in range(Start, End) to True for each input span. > > Scan the array and find metaspans - contig

Re: Merging overlapping spans/ranges

2005-05-10 Thread Mike Rovner
Max M wrote: > I am writing a "find-free-time" function for a calendar. There are a lot > of time spans with start end times, some overlapping, some not. > > To find the free time spans, I first need to convert the events into a > list of non overlapping time spans "meta-spans". > "Almost" lin

Re: Merging overlapping spans/ranges

2005-05-10 Thread elbertlev
The linear method: You create an array - one bool per minute. For one day 24 * 60 entries is enough. Spans (Start, End) are in minutes from midnight. Set array slots in range(Start, End) to True for each input span. Scan the array and find metaspans - contiguous sequences of False. -- http://ma

Re: Merging overlapping spans/ranges

2005-05-10 Thread Jordan Rastrick
Max M wrote: > I am writing a "find-free-time" function for a calendar. There are a lot > of time spans with start end times, some overlapping, some not. > > To find the free time spans, I first need to convert the events into a > list of non overlapping time spans "meta-spans". > > This nice asci

Re: Merging overlapping spans/ranges

2005-05-10 Thread bearophileHUGS
This is the problem of finding the connected components inside an interval graph. You can implement the algorithms yourself, of you can use my graph data structure here: http://sourceforge.net/projects/pynetwork/ The graph methods: createIntervalgGraph And: connectedComponents can probably solve

Merging overlapping spans/ranges

2005-05-10 Thread Max M
I am writing a "find-free-time" function for a calendar. There are a lot of time spans with start end times, some overlapping, some not. To find the free time spans, I first need to convert the events into a list of non overlapping time spans "meta-spans". This nice ascii graph should show what