M
Mark P
I'm working with a std::multiset and I want to efficiently select a
(continuous) range of elements in the set. What I know is that the
desired range is exactly those elements which compare equal to any of 3
"test elements" which I can easily construct (but which are not in the
multiset).
What makes this somewhat tricky is that if, say, no element compares
equal to the smallest test element, then there may be other subsequent
elements in the set (greater than the smallest test element and less
than the middle test element) which I do not want. So I can't just use
a lower_bound with the smallest test element and an upper_bound with the
largest test element. However, if there are elements in the set that
compare equal to one or more test elements, then I can be certain that
there are no intervening unwanted elements.
Presently I accomplish this by using equal_range for each test element,
and combining all non-empty output ranges. But this fails to exploit
the fact that all non-empty ranges must be consecutive. Is there an
algorithm in the STL which could make this more efficient?
If you're wondering, this is related to a scanline algorithm in
computational geometry.
Thanks for your help,
Mark
(continuous) range of elements in the set. What I know is that the
desired range is exactly those elements which compare equal to any of 3
"test elements" which I can easily construct (but which are not in the
multiset).
What makes this somewhat tricky is that if, say, no element compares
equal to the smallest test element, then there may be other subsequent
elements in the set (greater than the smallest test element and less
than the middle test element) which I do not want. So I can't just use
a lower_bound with the smallest test element and an upper_bound with the
largest test element. However, if there are elements in the set that
compare equal to one or more test elements, then I can be certain that
there are no intervening unwanted elements.
Presently I accomplish this by using equal_range for each test element,
and combining all non-empty output ranges. But this fails to exploit
the fact that all non-empty ranges must be consecutive. Is there an
algorithm in the STL which could make this more efficient?
If you're wondering, this is related to a scanline algorithm in
computational geometry.
Thanks for your help,
Mark