I would like to count the number of entries between two iterators of an std::multimap
in less than O(N) time. Are there any tricks or clever ways to do this?
Since std::multimap
has bidirectional iterators, my understanding is that something like std::distance
could do this in O(N) time.
Additional details: The multimap
's key is an N-tuple. I'm trying to find the number of entries in the multimap
whose key's first element is 0. The options for the first element of they key are 0 and 1, and the multimap
uses a strict weak ordering in which the first element of the key is always the most important. i.e., all elements with 0 come before any elements with 1.
Context: The iterators are returned by equal_range
, which runs in logarithmic time. Declaratively, I'd like to measure the length of the range.
Thank you.