views:

112

answers:

3

Hi,

is there a data structure, which stores its elements uniquely (for a given compare-Functor) but answers queries for the highest element in that data structure with respect to another compare-Function ?

For Example: I have a class with two properties :
1) the size
2) the value

I'd like to have a data structure which stores all elements uniquely regarding its size but answers queries for the element with the highest value.
Using std::set with a compare functor for the sizes gives me uniqueness but queries for the highest value will have linear runtime...
Is there a better way?

(I'll 'add elements then ask for the highest value' and keep iterating this until a certain termination point is reached)

Any information would be appreciated (papers etc)

+8  A: 

Boost::MultiIndex comes to mind.

peterchen
You beat me to it.
Matthieu M.
Hello, thank you everyone for your answers! It seems to me that this should/could be general knowledge, therefore I'll have to familiarize myself with the boost lib...
Dane
@Dane: it doesn't hurt ;) But I wouldn't have known of that particular lib if I hadn't searched for something similar some time before.
peterchen
A: 

Could it be a kd-tree (k-dimensional tree)? In your case, k would be 2.

ltcmelo
I guess... but it's much more complicated to implement that peterchen's solution
Matthieu M.
+1  A: 

What you want can be achieved using the library Boost.Multi-index

Check in particular this example in the tutorial, which is very close to your use case.

David Pierre