Re: data structures for efficient range queries

2009-10-20 Thread Sean Devlin
This is standard w/ Java 6. http://java.sun.com/javase/6/docs/api/java/util/NavigableMap.html On Oct 20, 11:16 am, Stuart Sierra wrote: > On Oct 20, 3:15 am, Volkan YAZICI wrote: > > > I think what you are after is an interval tree[1] data structure. You > > might find a suitable Java library

Re: data structures for efficient range queries

2009-10-20 Thread Stuart Sierra
On Oct 20, 3:15 am, Volkan YAZICI wrote: > I think what you are after is an interval tree[1] data structure. You > might find a suitable Java library or implement yours easily. > > Regards. > > [1]http://en.wikipedia.org/wiki/Interval_tree Yes, I think an interval tree is what you are looking fo

Re: data structures for efficient range queries

2009-10-20 Thread Timothy Pratley
On Oct 20, 2:19 pm, nchubrich wrote: > Thanks for the advice, everyone!  Timothy, I guess if you had non- > uniqueness but didn't care to have it indexed in more than one way you > could just take Alex's example and have his maps point to vectors, > right? Yup! --~--~-~--~~--

Re: data structures for efficient range queries

2009-10-20 Thread nchubrich
Thanks for the advice, everyone! Timothy, I guess if you had non- uniqueness but didn't care to have it indexed in more than one way you could just take Alex's example and have his maps point to vectors, right? --~--~-~--~~~---~--~~ You received this message bec

Re: data structures for efficient range queries

2009-10-20 Thread nchubrich
Sounds like the tree is what I need (since the data will be changing quite a bit). As for using a hash-map: wouldn't you need a sorted map to be able to pull out all the keys in a range? And then are the seq functions efficient for this? (I.E. if you drop a number of them to get to the beginnin

Re: data structures for efficient range queries

2009-10-20 Thread Volkan YAZICI
On Mon, 19 Oct 2009, nchubrich writes: > I need to make a data structure for a query such as "find everything > that is priced $3.27 - $6.12" (and perhaps sum up the total revenue > for all items in that price range). The naive way would be to make an > array with one slot for each increment in

Re: data structures for efficient range queries

2009-10-19 Thread Timothy Pratley
If the thing you want to index by is not unique, you could do... something like: (def m (atom (sorted-map))) (def rm (atom (sorted-map))) (defn add [k v] (swap! m assoc k v) (swap! rm assoc v (conj (get @rm v []) k))) (add 1 "bbb") (add 2 "ccc") (add 3 "aaa") (add 4 "aaa") ; @rm is now {

Re: data structures for efficient range queries

2009-10-19 Thread Alex Osborne
Alex Osborne wrote: > nchubrich wrote: >> I need to make a data structure for a query such as "find everything >> that is priced $3.27 - $6.12" (and perhaps sum up the total revenue >> for all items in that price range). > > > That's one of the things sorted maps are for: > > (let [objects-by-

Re: data structures for efficient range queries

2009-10-19 Thread Alex Osborne
nchubrich wrote: > I need to make a data structure for a query such as "find everything > that is priced $3.27 - $6.12" (and perhaps sum up the total revenue > for all items in that price range). That's one of the things sorted maps are for: (let [objects-by-price (sorted-map 0.50 :cookie, 5.0

Re: data structures for efficient range queries

2009-10-19 Thread Daniel Renfer
Would it be possible to use a hash-map with the prices as the keys and vectors of items as your values? That way you get efficient access to your values if you know the price and aren't paying for the empty space. On Oct 19, 2009 7:23 PM, "nchubrich" wrote: I need to make a data structure for a

Re: data structures for efficient range queries

2009-10-19 Thread Richard Newman
Two simple approaches: 1. Use a sorted, random-access data structure. A vector will suffice. Store your data in this. This is good if your data doesn't change much. Find the extremes of a range by binary search and linear walking. If that's too slow, build a metaindex, which is simply a prec

data structures for efficient range queries

2009-10-19 Thread nchubrich
I need to make a data structure for a query such as "find everything that is priced $3.27 - $6.12" (and perhaps sum up the total revenue for all items in that price range). The naive way would be to make an array with one slot for each increment in the entire range, and have each slot pointing to