I need a structure in which I can press key values when the keys are ordered in ascending order. If I request a value for a key, I would like to get the value of the nearest larger (but not equal) key inside the map.
So, for example, I press 100, 500 and 1000. If I ask for 750, I get a value of 1000. If I ask for 450, I get 500 Value. If I ask for 500, I get the value 1000. These keys are dynamic, the switch is not possible here.
My approach would be to push a class with a key and a value to a vector, but that would last in O (n).
Is there a better way / faster way to implement this instead of iterating ahead the key vector and comparing?
source
share