-
-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[std.algorithm.searching] Add extrema to compute min and max #8727
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit ElementType!Range
makes me wonder what happens when the elements are const
, immutable
, or shared
.
@@ -4035,6 +4036,132 @@ if (isInputRange!Range && !isInfinite!Range && | |||
assert(maxElement(arr) == S(145)); | |||
} | |||
|
|||
/** Returns an array of the minimum and maximum element in `r`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function should rather return a named tuple:
Tuple!(ElementType!Range, "min", ElementType!Range "max")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR please!
Performs
< 3n/2
comparisons, unlike the naive< 2n
.Implemented for an input range.
TODO add
alias map = a => a
parameter, once design is confirmed OK.