range-v3 icon indicating copy to clipboard operation
range-v3 copied to clipboard

drop_while view and sorted range : possible optimization?

Open ghost opened this issue 3 years ago • 4 comments

Hi, Reading drop_while page I think it would be handy to be able to tell that we are iterating an already sorted range, when applicable.

Right now, it seems to iterate every elements, whereas it could use a binary search to go faster.

ghost avatar Oct 30 '22 16:10 ghost

So you want an optimized drop_while where the range is_partitioned on the predicate.

JohelEGP avatar Oct 30 '22 18:10 JohelEGP

Actually my request holds for take_while and filter as well.

Range may be partitioned or not. But always sorted in regard to the criteria.

ghost avatar Oct 30 '22 18:10 ghost

Do you mean you would pass an argument telling it if the range is sorted? Otherwise, determining if the range is sorted would require iterating over every element anyway.

beojan avatar Nov 01 '22 23:11 beojan

Yes a boolean, Or a ::ranges::views::already_sorted flag.. like so

auto v = my_container | ::ranges::views::already_sorted | the rest

At this point, the dev takes the responsibility of this criteria and that the following drop_while/take_while/filter uses are coherent with this flag. otherwise, don't use this flag, and do just like right now.

It is just a speed optimization opportunity that may be used or not.

ghost avatar Nov 02 '22 06:11 ghost