Since there is no job less than next_work
in your buffer, your map can only contain such an element as its very first element. You could instead use begin()
to access your iterator, gaining the first element in constant time (and then test if it is the one you want). But what's still slowing down is the insertion, which will still be logarithmic in the current size of the buffer.
An alternative associative data-structure is a hash map. It supports expected constant-time insertion and look-up. It's not sorted by key, but since you only need to look-up an exact key this is not going to be a problem.
If your compiler supports C++11 (and you don't need to support pre-C++11 compilers), there is std::unordered_map
. Probably just replacing the class will solve it all. Maybe you need to adjust other accesses to the data structure which you didn't show in the code snipped, i.e. we don't know how you fill your data structure in fill_buffer
.
For C++03, you could try boost::unordered_map.