View source code
							
							
						
								Display the source code in std/algorithm/mutation.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								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.
							
						Module std.algorithm.mutation
This is a submodule of std.
It contains generic mutation algorithms.
| Function Name | Description | 
|---|---|
| bringToFront | If a = [1, 2, 3]andb = [4, 5, 6, 7],bringToFront(a, b)leavesa = [4, 5, 6]andb = [7, 1, 2, 3]. | 
| copy | Copies a range to another. If a = [1, 2, 3]andb = new int[5], thencopy(a, b)leavesb = [1, 2, 3, 0, 0]and returnsb[3 .. $]. | 
| fill | Fills a range with a pattern,
        e.g., if a = new int[3], thenfill(a, 4)leavesa = [4, 4, 4]andfill(a, [3, 4])leavesa = [3, 4, 3]. | 
| initializeAll | If a = [1.2, 3.4], theninitializeAll(a)leavesa = [double. | 
| move | move(a, b)movesaintob.move(a)readsadestructively when necessary. | 
| moveEmplace | Similar to movebut assumestargetis uninitialized. | 
| moveAll | Moves all elements from one range to another. | 
| moveEmplaceAll | Similar to moveAllbut assumes all elements intargetare uninitialized. | 
| moveSome | Moves as many elements as possible from one range to another. | 
| moveEmplaceSome | Similar to moveSomebut assumes all elements intargetare uninitialized. | 
| remove | Removes elements from a range in-place, and returns the shortened range. | 
| reverse | If a = [1, 2, 3],reverse(a)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], thenstrip(a, 1)andstrip!(e => e == 1)(a)returns[0]. | 
| stripLeft | Strips all leading elements equal to a value, or that satisfy a
        predicate.  If a = [1, 1, 0, 1, 1], thenstripLeft(a, 1)andstripLeft!(e => e == 1)(a)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], thenstripRight(a, 1)andstripRight!(e => e == 1)(a)returns[1, 1, 0]. | 
| swap | Swaps two values. | 
| swapAt | Swaps two values by indices. | 
| swapRanges | Swaps all elements of two ranges. | 
| uninitializedFill | Fills a range (assumed uninitialized) with a value. | 
Functions
| Name | Description | 
|---|---|
| 
									bringToFront(front, back)
								 | bringToFronttakes two rangesfrontandback, which may
be of different types. Considering the concatenation offrontandbackone unified range,bringToFrontrotates that unified
range such that all elements inbackare brought to the beginning
of the unified range. The relative ordering of elements infrontandback, respectively, remains unchanged. | 
| 
									copy(source, target)
								 | Copies the content of sourceintotargetand returns the
remaining (unfilled) part oftarget. | 
| 
									fill(range, value)
								 | Assigns valueto each element of input rangerange. | 
| 
									initializeAll(range)
								 | Initializes all elements of rangewith theirvalue.
Assumes that the elements of the range are uninitialized. | 
| 
									move(source, target)
								 | Moves sourceintotarget, via a destructive copy when necessary. | 
| 
									moveAll(src, tgt)
								 | Calls move(a, b)for each elementainsrcand the corresponding
elementbintgt, in increasing order. | 
| 
									moveEmplace(source, target)
								 | Similar to movebut assumestargetis uninitialized. This
 is more efficient becausesourcecan be blitted overtargetwithout destroying or initializing it first. | 
| 
									moveEmplaceAll(src, tgt)
								 | Similar to moveAllbut assumes all elements intgtare
 uninitialized. UsesmoveEmplaceto move elements fromsrcover elements fromtgt. | 
| 
									moveEmplaceSome(src, tgt)
								 | Same as moveSomebut assumes all elements intgtare
 uninitialized. UsesmoveEmplaceto move elements fromsrcover elements fromtgt. | 
| 
									moveSome(src, tgt)
								 | Calls move(a, b)for each elementainsrcand the corresponding
elementbintgt, in increasing order, stopping when either range has been
exhausted. | 
| 
									remove(range, offset)
								 | Eliminates elements at given offsets from rangeand returns the shortened
range. | 
| 
									remove(range)
								 | Reduces the length of the
bidirectional range rangeby removing
elements that satisfypred. Ifs = SwapStrategy,
elements are moved from the right end of the range over the elements
to eliminate. Ifs = SwapStrategy(the default),
elements are moved progressively to front such that their relative
order is preserved. Returns the filtered range. | 
| 
									reverse(r)
								 | Reverses rin-place.  Performsrevaluations ofswap.
UTF sequences consisting of multiple code units are preserved properly. | 
| 
									strip(range, element)
								 | The strip group of functions allow stripping of either leading, trailing, or both leading and trailing elements. | 
| 
									stripLeft(range, element)
								 | The strip group of functions allow stripping of either leading, trailing, or both leading and trailing elements. | 
| 
									stripRight(range, element)
								 | The strip group of functions allow stripping of either leading, trailing, or both leading and trailing elements. | 
| 
									swap(lhs, rhs)
								 | Swaps lhsandrhs. The instanceslhsandrhsare moved in
memory, without ever callingopAssign, nor any other function.Tneed not be assignable at all to be swapped. | 
| 
									swapAt(r, i1, i2)
								 | Swaps two elements in-place of a range r,
specified by their indicesi1andi2. | 
| 
									swapRanges(r1, r2)
								 | Swaps all elements of r1with successive elements inr2.
Returns a tuple containing the remainder portions ofr1andr2that 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(range, value)
								 | Initializes each element of rangewithvalue.
Assumes that the elements of the range are uninitialized.
This is of interest for structs that
define copy constructors (for all other types,filland
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 totoUpper(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. | 
Authors
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.