[std.algorithm.searching] Add extrema to compute min and max#8727
[std.algorithm.searching] Add extrema to compute min and max#8727dlang-bot merged 4 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8727" |
|
@atilaneves This is a new public function |
aa71b1d to
3d2892c
Compare
Unlike the naive version done where? |
https://dlang.org/phobos/std_algorithm_iteration.html#fold
|
Do you mean |
|
@atilaneves |
|
@ntrel @atilaneves how do we move further with this? |
|
I still don't know what this is a replacement for. |
|
When a user wants to compute the min and max value of a range with Phobos, currently they need to call |
| * r = The range to traverse. | ||
| */ | ||
| // TODO alias map = a => a | ||
| ElementType!Range[2] extrema(Range)(Range r) |
There was a problem hiding this comment.
The explicit ElementType!Range makes me wonder what happens when the elements are const, immutable, or shared.
| assert(maxElement(arr) == S(145)); | ||
| } | ||
|
|
||
| /** Returns an array of the minimum and maximum element in `r`. |
There was a problem hiding this comment.
I think this function should rather return a named tuple:
Tuple!(ElementType!Range, "min", ElementType!Range "max")
Performs
< 3n/2comparisons, unlike the naive< 2n.Implemented for an input range.
TODO add
alias map = a => aparameter, once design is confirmed OK.