El Marcel
El Marcel

Reputation: 1785

Looking for a stl multimap like container that allows looking for a key by value

I'm in 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:

  1. multiple values per key
  2. very fast lookup by key
  3. insertion/deletion speed not important
  4. 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.

Upvotes: 1

Views: 95

Answers (2)

Juraj Blaho
Juraj Blaho

Reputation: 13451

Try Boost.Multi-Index.

Upvotes: 3

Yakov Galka
Yakov Galka

Reputation: 72469

Boost.MultiIndex is what you need.

Upvotes: 2

Related Questions