Bug 15385 – Apply Andersson91 idea to SortedRange.contains

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-11-28T20:02:00Z
Last change time
2016-01-11T20:50:39Z
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2015-11-28T20:02:00Z
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.
Comment #1 by github-bugzilla — 2015-11-30T01:34:39Z
Comment #2 by github-bugzilla — 2016-01-03T14:15:06Z