Re: efficient interval containment lookup

2009-01-13 Thread Tim Chase
Per Freem wrote: i forgot to add, my naive_find is: def naive_find(intervals, start, stop): results = [] for interval in intervals: if interval.start >= start and interval.stop <= stop: results.append(interval) return results I don't know if using a list-comprehension here is a

Re: efficient interval containment lookup

2009-01-13 Thread Gabriel Genellina
En Tue, 13 Jan 2009 02:55:36 -0200, Per Freem escribió: On Jan 12, 10:58 pm, Steven D'Aprano wrote: On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > thanks for your replies -- a few clarifications and questions. the > is_within operation is containment, i.e. (a,b) is within (c,d) iff

Re: efficient interval containment lookup

2009-01-12 Thread brent
On Jan 12, 9:34 pm, Per Freem wrote: > hi brent, thanks very much for your informative reply -- didn't > realize this about the size of the interval. > > thanks for the bx-python link.  could you (or someone else) explain > why the size of the interval makes such a big difference? i don't > unders

Re: efficient interval containment lookup

2009-01-12 Thread Steven D'Aprano
On Mon, 12 Jan 2009 20:55:36 -0800, Per Freem wrote: > on one run, i get: > interval tree: 8584.682 > brute force: 8201.644 Here are three runs on my computer: interval tree: 10132.682 brute force: 12054.988 interval tree: 10355.058 brute force: 12119.227 interval tree: 9975.414 brute force:

Re: efficient interval containment lookup

2009-01-12 Thread Per Freem
hi brent, thanks very much for your informative reply -- didn't realize this about the size of the interval. thanks for the bx-python link. could you (or someone else) explain why the size of the interval makes such a big difference? i don't understand why it affects efficiency so much... thanks

Re: efficient interval containment lookup

2009-01-12 Thread brent
On Jan 12, 8:55 pm, Per Freem wrote: > On Jan 12, 10:58 pm, Steven D'Aprano > > > > wrote: > > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > > thanks for your replies -- a few clarifications and questions. the > > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a >

Re: efficient interval containment lookup

2009-01-12 Thread Per Freem
i forgot to add, my naive_find is: def naive_find(intervals, start, stop): results = [] for interval in intervals: if interval.start >= start and interval.stop <= stop: results.append(interval) return results On Jan 12, 11:55 pm, Per Freem wrote: > On Jan 12, 10:58 pm, Steven D'A

Re: efficient interval containment lookup

2009-01-12 Thread Per Freem
On Jan 12, 10:58 pm, Steven D'Aprano wrote: > On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > > thanks for your replies -- a few clarifications and questions. the > > is_within operation is containment, i.e. (a,b) is within (c,d) iff a > >>= c and b <= d. Note that I am not looking for inte

Re: efficient interval containment lookup

2009-01-12 Thread Steven D'Aprano
On Mon, 12 Jan 2009 14:49:43 -0800, Per Freem wrote: > thanks for your replies -- a few clarifications and questions. the > is_within operation is containment, i.e. (a,b) is within (c,d) iff a >>= c and b <= d. Note that I am not looking for intervals that > overlap... this is why interval trees s

Re: efficient interval containment lookup

2009-01-12 Thread Per Freem
thanks for your replies -- a few clarifications and questions. the is_within operation is containment, i.e. (a,b) is within (c,d) iff a >= c and b <= d. Note that I am not looking for intervals that overlap... this is why interval trees seem to me to not be relevant, as the overlapping interval pro

Re: efficient interval containment lookup

2009-01-12 Thread Steven D'Aprano
On Mon, 12 Jan 2009 11:36:47 -0800, Per Freem wrote: > hello, > > suppose I have two lists of intervals, one significantly larger than the > other. [...] > What is an efficient way to this? One simple way is: http://en.wikipedia.org/wiki/Interval_tree > for a_range in listA: > for b_range i

Re: efficient interval containment lookup

2009-01-12 Thread Robert Kern
[Apologies for piggybacking, but I think GMane had a hiccup today and missed the original post] [Somebody wrote]: suppose I have two lists of intervals, one significantly larger than the other. For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain thousands of elements while li

Re: efficient interval containment lookup

2009-01-12 Thread Scott David Daniels
Are these ranges constrained in any way? Does preprocessing count in the efficiency cost? Is the long list or the short list fixed while the other varies? With no constraints the problem is harder. > But perhaps there's a way to index this that makes things more > efficient? I.e. a smart way of

Re: efficient interval containment lookup

2009-01-12 Thread Tim Chase
suppose I have two lists of intervals, one significantly larger than the other. For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain thousands of elements while listB (of the same form) might contain hundreds of thousands or millions of elements. I want to count how many interval

efficient interval containment lookup

2009-01-12 Thread Per Freem
hello, suppose I have two lists of intervals, one significantly larger than the other. For example listA = [(10, 30), (5, 25), (100, 200), ...] might contain thousands of elements while listB (of the same form) might contain hundreds of thousands or millions of elements. I want to count how many i