tags:

views:

139

answers:

3

Hi, I'm wondering if any of you know of a c++ associative map container type which I can perform multiple key lookups on. The map needs to have constant time lookups but I don't care if it's ordered or unordered. It just needs to be fast.

For example, I want to store a bunch of std::vector objects in a map with an integer and a void* as the lookup keys. Both the int and the void* must match for my vector to be retrieved. Does anything like this exist already? Or am I going to have to roll my own. If so, any suggestions? I've been trying to store a boost::unordered_map inside another boost::unordered_map, but I have not had any success with this method yet. Maybe I will continue Pershing this method if there is no simpler way. Thanks!

A: 

You could use boost::multi_index.

(although I think what you actually want is to use a type that contains both the void* and the integer as the key to your map, and just to compare the raw data for both in order to provide the comparison operator for the map)

Autopulated
+3  A: 

Constant look up requires a hash map. You can use a the boost::unordered_map (or tr1). The key would be the combined hash of the int and the void pointer.

pmr
This is exactly what I was looking for. Thanks!
Morgan
A: 

If you don't want to use boost, you can try map< int, map<void*, vector> >. The lookups are however O(log(map size)).

Vlad