-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Description
I would like to do a binary search without having to materialize the array:
I would prefer not to build the array, because my function is not i->i^2 but expensive to calculate.
searchsortedfirst([i^2 for i in 1:10], 25) # is working
searchsortedfirst((i^2 for i in 1:10), 25) # no method
searchsortedfirst(1:10, 25, by=i->i^2) # does not what I had expected
It looks like an implementation error, that the by=transform is applied to the value to compare with.
There are at least 2 arguments against the current implementation:
- It forces the user to pre-calculate an abstract vector with the transformed values
- the transform of the comparison value is performed as many times as comparisons are made in the algorithm
- the documentation does not suggest, that the comparison value is treated this way
Metadata
Metadata
Assignees
Labels
No labels