D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15385 - Apply Andersson91 idea to SortedRange.contains
Summary: Apply Andersson91 idea to SortedRange.contains
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-28 20:02 UTC by Andrei Alexandrescu
Modified: 2016-01-11 20:50 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2015-11-28 20:02:00 UTC
http://user.it.uu.se/~arnea/ps/searchproc.pdf describes a simple trick that reduces the number of comparisons in a binary search.

The same idea can be used for binary search in an array. The idea is to save an index (not a node as described in the paper). In

https://github.com/D-Programming-Language/phobos/blob/master/std/range/package.d#L7833

the routine could do only one evaluation of predFun and then continue searching. Only when the count goes down to zero is the other comparison done.