ocean.core.array.Mutation

Collection of utilities to modify arrays and buffers in-place.

All functions in this module only work on mutable arguments and modify them in place. New memory must never be allocated.

Based on tango.core.Array module from Tango library.

Members

Functions

append
DE[] append(Buffer!(DE) dest, T arrays)

Copies the contents of one element of arrays to another, starting at deststart, setting the length of the destination array first. Note that start may be greater than the initial length of dest; dest will then be extended appropriately.

append
DE[] append(DE[] dest, T arrays)
Undocumented in source. Be warned that the author may not have intended to support it.
appendCopy
void appendCopy(Buffer!(T)[] dest, T2[] src)

Appends an element to a list of arrays, and copies the contents of the passed source array into the new element, setting the length of the destination array first.

appendCopy
void appendCopy(T[][] dest, T2[] src)
Undocumented in source. Be warned that the author may not have intended to support it.
clear
T[] clear(T[] array)

Resets each elements of array to its initial value.

concat
DE[] concat(Buffer!(DE) dest, T arrays)

Concatenates a list of arrays into a destination array. The function results in at most a single memory allocation, if the destination array is too small to contain the concatenation results.

concat
DE[] concat(DE[] dest, T arrays)
Undocumented in source. Be warned that the author may not have intended to support it.
containsDuplicate
bool containsDuplicate(T[] array)

Sorts array and checks if it contains at least one duplicate.

copy
T[] copy(Buffer!(T) dest, T2[] src)

Copies the contents of one array to another, setting the length of the destination array first.

copy
T[] copy(T[] dest, T2[] src)
Undocumented in source. Be warned that the author may not have intended to support it.
copyExtend
T[] copyExtend(Buffer!(T) dest, T2[] src)

Copies the contents of src to dest, increasing dest.length if required. Since dest.length will not be decreased, dest will contain tailing garbage if src.length < dest.length.

copyExtend
T[] copyExtend(T[] dest, T2[] src)
Undocumented in source. Be warned that the author may not have intended to support it.
distinct
size_t distinct(T[] array, Pred pred)
size_t distinct(Buffer!(T) array, Pred pred)

Performs a linear scan of complete array, moving all but the first element of each consecutive group of duplicate elements to the end of the sequence. The relative order of all remaining elements will be preserved. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

filterInPlace
size_t filterInPlace(T[] array, Exclude exclude)

Moves all elements from array which match the exclusion criterum represented by exclude to the back of array so that the elements that do not match this criterium are in the front.

findDuplicates
int findDuplicates(T[] array, int delegate(ref size_t index, ref T element) found)

Sorts array and iterates over each array element that compares equal to the previous element.

insertShift
T[] insertShift(Buffer!(T) buffer, size_t index, size_t insert_elems)

Inserts elements into the middle of a buffer, maintaining the order of the existing elements by shifting them right using memmove.

insertShift
T[] insertShift(T[] buffer, size_t index, size_t insert_elems)
Undocumented in source. Be warned that the author may not have intended to support it.
isClearable
bool isClearable()

Checks if T.init consists only of zero bytes so that a T[] array can be cleared by clear().

moveToEnd
size_t moveToEnd(T[] array, T element, Pred pred)
size_t moveToEnd(Buffer!(T) array, T element, Pred pred)

Performs a linear scan of complete array, moving all items matching element to the end of the sequence. The relative order of items not matching the matching element will be preserved. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

partition
size_t partition(T[] array, Pred pred)
size_t partition(Buffer!(T) array, Pred pred)

Partitions array such that all elements that satisfy pred will be placed before the elements that do not satisfy pred. The algorithm is not required to be stable.

pop
bool pop(Buffer!(T) buffer, T popped)

Removes and returns (via the 'popped' out parameter) the last element in an array. If the provided array is empty, the function returns false.

pop
bool pop(T[] array, T popped)
Undocumented in source. Be warned that the author may not have intended to support it.
quickselect
T quickselect(T[] arr, size_t k, Pred pred, size_t initial_pivot_index)

Same as select with two changes:

removeIf
size_t removeIf(T[] array, Pred pred)
size_t removeIf(Buffer!(T) array, Pred pred)

Performs a linear scan of complete array, removing all elements that satisfy pred from the sequence. The relative order of elements that do not satisfy pred will be preserved.

removeShift
T[] removeShift(Buffer!(T) buffer, size_t index, size_t remove_elems)

Removes elements from the middle of a buffer, maintaining the order of the remaining elements by shifting them left using memmove.

removeShift
T[] removeShift(T[] buffer, size_t index, size_t remove_elems)
Undocumented in source. Be warned that the author may not have intended to support it.
replace
size_t replace(T[] array, T element, T new_element, Pred pred)
size_t replace(Buffer!(T) array, T element, T new_element, Pred pred)

Performs a linear scan of complete array, replacing occurrences of specified element with the new element. Comparisons will be performed using the supplied predicate or '==' if none is supplied.

replaceIf
size_t replaceIf(T[] array, T new_element, Pred pred)
size_t replaceIf(Buffer!(T) array, T new_element, Pred pred)

Performs a linear scan of the complete array, replacing elements where pred returns true.

reverse
T[] reverse(T[] array)

Swaps elements of argument array so they all come in reverse order

select
size_t select(T[] arr, size_t k, Pred pred)

Selects the kth element of an array as defined by the given predicate.

shuffle
T[] shuffle(T[] array, double rand)

Shuffles the elements of array in-place.

shuffle
T[] shuffle(T[] array, size_t delegate(size_t i) new_index)

Shuffles the elements of array in-place.

sort
T[] sort(T[] array, Pred pred)

Sorts array using the supplied predicate or '<' if none is supplied. The algorithm is not required to be stable. The current implementation is based on quicksort, but uses a three-way partitioning scheme to improve performance for ranges containing duplicate values (Bentley and McIlroy, 1993).

uniq
T[] uniq(T[] array)

Sorts array and removes all value duplicates.

verifySelect
void verifySelect(T[] buf, size_t k, T expected_value)
Undocumented in source. Be warned that the author may not have intended to support it.

Meta

License

Tango Dual License: 3-Clause BSD License / Academic Free License v3.0. See LICENSE_TANGO.txt for details.