I have some pairs std::pair<X, Y>. X is unique and will never change and Y will be regularly updated. The pairs need to be sorted based on Y but I also want quick retrieval of a X to update a Y.
Until now I used std::set<std::pair<X, Y>, CustomCompare> to get the sorted list based on Y. However updates are now slow, I think in the worst case I need to run through the whole set to find the correct X. Am I right?
Is there any datastructure that supports sorting using Y plus quick (O(logn) or less) retrieval of X? I'm open to the idea of using a supporting data structure or splitting up X and Y.
EDIT: Maybe an example will clear things up. Let's say X is a name and Y is monthly salary. So a pair could be ("John", 5000). Now I need a list/set of people sorted by the highest salary, for example [("Mary", 8000), ("John", 5000), ("Chris", 2000)]. Additionaly, I need a way to lookup a person (in O(1) or O(logn)), so that I can remove the name-salary pair from the list/set, update the salary and then re-insert the name-salary pair into the sorted list/set. Updates occur very frequently.