Data-structure that stores unique elements but answers queries for another ordering in C++
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 valueI'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)
Boost::MultiIndex comes to mind.
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.
Could it be a kd-tree (k-dimensional tree)? In your case, k would be 2.
精彩评论