|Keep It Simple, Stupid|
multi-dimensional range lookupby danmcc (Novice)
|on May 08, 2007 at 19:30 UTC||Need Help??|
danmcc has asked for the
wisdom of the Perl Monks concerning the following question:
I have a large swathe of color information about a photo collection in RGB format. Given a range of RGB values, I would like to retrieve photos containing those colors.
Right now, all this data is in a database table, with four columns: a red value, a green value, a blue value, and a photo ID. Lookups now occur in some sort of fashion like: select photo_id from colors where r in (12,13,14,15) and g in (78,79,80,81) and b in (23,24,25,26)
This takes a long time.
I would like to put all this information in a giant in-memory data structure for super-fast lookups. But just what sort of data structure I need escapes my current spiritual wisdom.
A brute force approach of pre-compiling all possible RGB combinations and the photos they correspond to is possible, but I'm hoping a lone monk out there might know of a more elegant approach.