View source code
Display the source code in std/algorithm/mutation.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.
Module std.algorithm.mutation
This is a submodule of std.algorithm. It contains generic mutation algorithms.
Function Name | Description |
---|---|
bringToFront |
If a = [1, 2, 3] and b = [4, 5, 6, 7] ,
leaves a = [4, 5, 6] and
b = [7, 1, 2, 3] . |
copy |
Copies a range to another. If
a = [1, 2, 3] and b = new int[5] , then
leaves b = [1, 2, 3, 0, 0] and returns b[3 .. $] . |
fill |
Fills a range with a pattern,
e.g., if a = new int[3] , then
leaves a = [4, 4, 4] and leaves
a = [3, 4, 3] . |
initializeAll |
If a = [1.2, 3.4] , then leaves
a = [double.init, double.init] . |
move |
moves a into b . reads a
destructively. |
moveAll | Moves all elements from one range to another. |
moveSome | Moves as many elements as possible from one range to another. |
remove | Removes elements from a range in-place, and returns the shortened range. |
reverse |
If a = [1, 2, 3] , changes it to [3, 2, 1] . |
strip |
Strips all leading and trailing elements equal to a value, or that
satisfy a predicate.
If a = [1, 1, 0, 1, 1] , then and
returns [0] . |
stripLeft |
Strips all leading elements equal to a value, or that satisfy a
predicate. If a = [1, 1, 0, 1, 1] , then and
returns [0, 1, 1] . |
stripRight |
Strips all trailing elements equal to a value, or that satisfy a
predicate.
If a = [1, 1, 0, 1, 1] , then and
returns [1, 1, 0] . |
swap | Swaps two values. |
swapRanges | Swaps all elements of two ranges. |
uninitializedFill | Fills a range (assumed uninitialized) with a value. |
Functions
Name | Description |
---|---|
bringToFront
|
The function has considerable flexibility and
usefulness. It can rotate elements in one buffer left or right, swap
buffers of equal length, and even move elements across disjoint
buffers of different types and different lengths.
|
copy
|
Copies the content of into and returns the
remaining (unfilled) part of .
|
fill
|
Assigns to each element of input range .
|
fill
|
Fills with a pattern copied from . The length of
does not have to be a multiple of the length of . If is empty, an exception is thrown.
|
initializeAll
|
Initializes all elements of with their .init value.
Assumes that the elements of the range are uninitialized.
|
move
|
Moves into via a destructive copy .
|
moveAll
|
For each element a in and each element b in in lockstep in increasing order, calls .
|
moveSome
|
For each element a in and each element b in in lockstep in increasing order, calls . Stops
when either or have been exhausted.
|
remove
|
Eliminates elements at given offsets from and returns the
shortened range . In the simplest call, one element is removed.
|
remove
|
Reduces the length of the bidirectional range by removing
elements that satisfy pred . If s = ,
elements are moved from the right end of the range over the elements
to eliminate. If s = (the default),
elements are moved progressively to front such that their relative
order is preserved. Returns the filtered range .
|
reverse
|
Reverses in-place. Performs r.length / 2 evaluations of .
|
reverse
|
Reverses r in-place, where r is a narrow string (having
elements of type char or wchar ). UTF sequences consisting of
multiple code units are preserved properly.
|
strip
|
The strip group of functions allow stripping of either leading, trailing,
or both leading and trailing elements.
|
stripLeft
|
The strip group of functions allow stripping of either leading, trailing,
or both leading and trailing elements.
|
stripRight
|
The strip group of functions allow stripping of either leading, trailing,
or both leading and trailing elements.
|
swap
|
Swaps and . The instances and are moved in
memory, without ever calling opAssign , nor any other function. T
need not be assignable at all to be swapped.
|
swapRanges
|
Swaps all elements of with successive elements in .
Returns a tuple containing the remainder portions of and that were not swapped (one of them will be empty). The ranges may
be of different types but must have the same element type and support
swapping.
|
uninitializedFill
|
Initializes each element of with .
Assumes that the elements of the range are uninitialized.
This is of interest for structs that
define copy constructors (for all other types, fill and
uninitializedFill are equivalent).
|
Enums
Name | Description |
---|---|
SwapStrategy
|
Defines the swapping strategy for algorithms that need to swap
elements in a range (such as partition and sort). The strategy
concerns the swapping of elements that are not the core concern of the
algorithm. For example, consider an algorithm that sorts [ "abc",
"b", "aBc" ] according to toUpper(a) < toUpper(b) . That
algorithm might choose to swap the two equivalent strings "abc"
and "aBc" . That does not affect the sorting since both [
"abc", "aBc", "b" ] and [ "aBc", "abc", "b" ] are valid
outcomes.
|