I'm having a map<double, unique_ptr<Item>>
. I would like to search this map, to find the item where a computed value is closest to the search value. The computed value can be generated by Item::compute
which is a length computation, that I would like avoid doing for all elements. It can be assumed that this map is already ordered according to the results of the compute function.
So I thought that I could make a binary search, but the problem is, that I cannot really jump to the nth element in the map, since it is a map and not a vector. More specifically, I would need to get the middle item between two arbitrary items in the map. Is that possible? Is there a way an efficiant way to perform binary search within a map?