Looking for a stl multimap like container that allows looking for a key by value
I'm i开发者_如何转开发n need to lookup the key from a particular element. It doesn't have to be very fast, but it should be better that iterating through all values.
In particular, this is my problem space:
- multiple values per key
- very fast lookup by key
- insertion/deletion speed not important
- key lookup from value that does better than O(n)
Does anyone know a datastructure that's useful in this situation, or would it be better to just have a map and a multimap side by side?
Solved. I actually ended up requesting the user give the key too. From an oo standpoint a horrible solution, but from a performance standpoint way faster. Dince the method I need the lookup for has a value parameter, the user can store the key next to the value.
Try Boost.Multi-Index.
Boost.MultiIndex is what you need.
精彩评论