I'm looking for 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 int
and a void*
as the lookup keys. Both the int
and the void*
must match for my vector to be retrieved.
Does such a container exist already? Or am I going to have to roll my own? If so, how could I implement it? 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.
Class MultiKeyMap<K,V> A Map implementation that uses multiple keys to map the value. This class is the most efficient way to uses multiple keys to map to a value.
You can't have an hash map with multiple keys, but you can have an object that takes multiple parameters as the key. Create an object called Index that takes an x and y value. Then have your HashMap<Index, Value> to get your result. :) You need to override hashCode and equals .
HashMap can be one of the best data structures for mapping multiple keys to the same value.
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.
If you don't want to use boost, you can try map< int, map<void*, vector> >
. The lookups are however O(log(map size)).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With