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 r in three adjacent ranges and returns them. The first and leftmost range only contains elements in r less than pivot. The second and middle range only contains elements in r that are equal to pivot. Finally, the third and rightmost range only contains elements in r that are greater than pivot. The less-than test is defined by the binary function 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

NameDescription
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 partition3 has not been implemented yet.

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 ]);

Authors

Andrei Alexandrescu

License

Boost License 1.0.

Comments