Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12494
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: lookup by EnumSet |
| References | <3kmpk7lno3fehkr0o21b4dqvhoijmpehbq@4ax.com> |
| Message-ID | <QC73r.9650$Ai4.1394@newsfe18.iad> (permalink) |
| Date | 2012-02-28 08:51 -0800 |
On 2/28/12 5:55 AM, Roedy Green wrote: > I had a long and annoying dream that there was a Java Collection that > let you look up by EnumSet. It was not a simple Map. > > It worked something like this: You could assign a set of binary > attributes to a Person, e.g. male/female, fat, thin, average, atheist, > Christian, Moslem, Jew, Buddhist. Asian, European, African, North > American, South American.. > > Then you could ask for all the fat or average females, Buddhist but > not Asian. > > You might specify an EnumSet for what you want and one for what you > don't want. Anything not specified in either does not matter. > > In the dream I was trying to write example code and an entry in the > Java glossary. When I woke, I could not think of such a class, and > further it was not obvious how one could be implemented. > > I wondered how you would do it. > > I thought you might extract the attributes into an array of longs and > check each one for compliance with your masks. > > If the sets were stable, you might extract a BitSet for each > attribute, and do logical operations on giant bit strings of the > relevant bits. > > I vaguely recall SQL databases optimising queries of this type by > transparently building inverse look up indexed. As many have said indirectly, it sounds like an RDBMS problem. For a small enough data set, you could fit the indexes in memory, either as a Collection<Person>, or if you're more space conscious a BitSet where the bit number corresponds to a List<Person> index. would be one approach. For example, Solr uses such a BitSet of "Document Index" to cache its Lucene query results. If you need to find intersections or unions, BitSets are fairly cheap if your data set is small enough. One technique RDBMS query optimization algorithms use is to estimate which index-based query would result in the smallest set, and then iterate through each of those, filtering out ones that don't match other parts of the query.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
lookup by EnumSet Roedy Green <see_website@mindprod.com.invalid> - 2012-02-28 05:55 -0800
Re: lookup by EnumSet Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-02-28 07:03 -0800
Re: lookup by EnumSet Roedy Green <see_website@mindprod.com.invalid> - 2012-02-28 15:22 -0800
Re: lookup by EnumSet Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-02-28 09:27 -0600
Re: lookup by EnumSet Lew <noone@lewscanon.com> - 2012-02-28 09:31 -0800
Re: lookup by EnumSet Robert Klemme <shortcutter@googlemail.com> - 2012-02-28 23:08 +0100
Re: lookup by EnumSet Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-02-28 08:51 -0800
Re: lookup by EnumSet Robert Klemme <shortcutter@googlemail.com> - 2012-02-28 23:08 +0100
Re: lookup by EnumSet Robert Klemme <shortcutter@googlemail.com> - 2012-03-01 01:22 -0800
Re: lookup by EnumSet Wanja Gayk <brixomatic@yahoo.com> - 2012-02-29 11:06 +0100
csiph-web