View source code
Display the source code in std/algorithm/sorting.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.algorithm.sorting.partition3
Rearranges elements in
in three adjacent ranges and returns
them. The first and leftmost range only contains elements in r
less than r
. The second and middle range only contains
elements in pivot
that are equal to r
. Finally, the third
and rightmost range only contains elements in pivot
that are greater
than r
. The less-than test is defined by the binary function
pivot
less
.
Prototype
auto partition3(alias less, std.algorithm.mutation.SwapStrategy ss, Range, E)( Range r, E pivot ) if (ss == SwapStrategy.unstable && isRandomAccessRange!Range && hasSwappableElements!Range && hasLength!Range && is(typeof(binaryFun!less(r.front, pivot)) == bool) && is(typeof(binaryFun!less(pivot, r.front)) == bool) && is(typeof(binaryFun!less(r.front, r.front)) == bool));
Parameters
Name | Description |
---|---|
less | The predicate to use for the rearrangement. |
ss | The swapping strategy to use. |
r | The random-access range to rearrange. |
pivot | The pivot element. |
Returns
A std.typecons.Tuple
of the three resulting ranges. These ranges are
slices of the original range.
BUGS
stable
has not been implemented yet.
partition3
Example
auto a = [ 8, 3, 4, 1, 4, 7, 4 ]; auto pieces = partition3(a, 4); assert(pieces[0] == [ 1, 3 ]); assert(pieces[1] == [ 4, 4, 4 ]); assert(pieces[2] == [ 8, 7 ]);