I need to store objects that have a number (>2) of integer member variables and do quick look-ups using any member variables as a search key.
For easier illustration let’s say the objects are tuples of 3 integers and I need to do quick look-ups using any element of a tuple as a key in a list of such tuples:
collection = [(1, 200, 9),
(2, 300, 8),
(3, 400, 7)]
Look-ups would be like:
collection.lookup_by_first_element(1) # Return (1, 200, 9)
collection.lookup_by_second_element(300) # Return (2, 300, 8)
collection.lookup_by_third_element(250) # Return None
I need the lookups to be fast/efficient. My best bet so far is to use an in memory sqlite database with three columns for the three tuple elements and put indexes on all three columns.
A search tree would also do, but those have one key for lookup and I don’t see how could I do lookups based on more than one key. How would you do it?
Using numpy: