Find on sorted range slower?

Timon Gehr via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 7 03:01:38 PDT 2015


On 08/07/2015 11:03 AM, Tofu Ninja wrote:
> On Friday, 7 August 2015 at 08:18:04 UTC, Nordlöw wrote:
>> On Friday, 7 August 2015 at 05:21:32 UTC, Tofu Ninja wrote:
>>> HAHAH wow, this is hilarious, I just checked, nothing in std.algo
>>> takes advantage of sorted ranges, sort doesn't even take advantage of
>>> it! You pass a sorted range into sort and it will just resort it!
>>> Wow....
>>
>> Who fixes this?
>>
>> I can look into it... is there an issue for this?
>
> I have no idea, but it is pretty silly. Sort/isSorted on a sorted range
> should be a nop. Find and friends, should do doing some kind of binary
> search. Max and min should be O(1). Some of the functions that return a
> sub range or a mutated range could probably be returning sorted ranges
> as well if its input is a sorted range, remove, strip and split at least
> could.

Binary search is not always faster than linear search.


More information about the Digitalmars-d-learn mailing list