ae.utils.array

Array utility functions

Public Imports

ae.utils.aa
public import ae.utils.aa;
Undocumented in source.
ae.utils.appender
public import ae.utils.appender;
Undocumented in source.

Members

Aliases

queuePush
alias queuePush = stackPush

Push val into arr, treating it like a queue.

Enums

OnEof
deprecated enum OnEof
Undocumented in source.

Functions

as
inout(T) as(inout(ubyte)[] bytes)

Reverse of .asBytes

asort
auto asort(T[] arr)
Undocumented in source. Be warned that the author may not have intended to support it.
auniq
auto auniq(T[] arr)
Undocumented in source. Be warned that the author may not have intended to support it.
contains
bool contains(T[] arr, V val)

Whether array contains value, no BS.

contains
bool contains(T[] str, U[] what)

Ditto, for substrings

containsAt
bool containsAt(T[] haystack, T[] needle, size_t offset)

Like startsWith, but with an offset.

countSort
void countSort(T[] arr, T[] valuesBuf, size_t[] countsBuf)

Sorts arr in-place using counting sort. The difference between the lowest and highest return value of orderPred(arr[i]) shouldn't be too big.

countSort
void countSort(T[] arr)
Undocumented in source. Be warned that the author may not have intended to support it.
eat
deprecated bool eat(T[] arr, T[] prefix)

If arr starts with prefix, slice it off and return true. Otherwise leave arr unchaned and return false.

elementIndex
size_t elementIndex(const(T)[] arr, T element)

Given an array and a reference to an element inside it, returns its index. The reverse operation of indexing an array.

emptySlice
auto emptySlice()

Returns an empty, but non-null slice of T.

fromBytes
deprecated inout(T) fromBytes(inout(ubyte)[] bytes)
Undocumented in source. Be warned that the author may not have intended to support it.
fromBytes
deprecated inout(T) fromBytes(inout(ubyte)[] bytes)
Undocumented in source. Be warned that the author may not have intended to support it.
get
T get(T[] arr, size_t index)

Like AA.get - soft indexing, throws an Exception (not an Error) on out-of-bounds, even in release builds.

get
auto get(T[] arr, size_t index, T defaultValue)

Like AA.get - soft indexing, returns default value on out-of-bounds.

getExpand
T getExpand(T[] arr, size_t index)

Expand the array if index is out-of-bounds.

indexOf
ptrdiff_t indexOf(T[] arr, D val)

Complement to std.string.indexOf which works with arrays of non-character types. Unlike std.algorithm.countUntil, it does not auto-decode, and returns an index usable for array indexing/slicing.

indexOf
ptrdiff_t indexOf(T[] arr, T[] val)
Undocumented in source. Be warned that the author may not have intended to support it.
indexOfElement
deprecated ptrdiff_t indexOfElement(T[] arr, D val)
Undocumented in source. Be warned that the author may not have intended to support it.
isIdentical
bool isIdentical(T a, T b)

A more generic alternative to the "is" operator, which doesn't have corner cases with static arrays / floats.

isIn
bool isIn(T val, T[] arr)

Returns true if one of the elements of arr contains val.

isOneOf
bool isOneOf(T val, T[] arr)

Returns true if one of the elements of arr contains val.

list
auto list(Args args)

Equivalent of PHP's list language construct: http://php.net/manual/en/function.list.php

Works with arrays and tuples. Specify null as an argument to ignore that index (equivalent of list(x, , y) in PHP).

memcmp
int memcmp(ubyte[] a, ubyte[] b)

C memcmp wrapper.

memmove
void memmove(T[] dst, T[] src)

Like std.algorithm.copy, but without the auto-decode bullshit. https://issues.dlang.org/show_bug.cgi?id=13650

nonNull
T[] nonNull(T[] arr)

Ensure that arr is non-null if empty.

padRight
T[] padRight(T[] s, size_t l, T c)

Return s expanded to at least l elements, filling them with c.

pluck
T pluck(T[] arr)

Select and return a random element from the array, and remove it from the array.

putExpand
T putExpand(T[] arr, size_t index, T value)

Expand the array if index is out-of-bounds.

queuePeek
T queuePeek(T[] arr)

Peek at the front of arr, treating it like a queue.

queuePeekLast
T queuePeekLast(T[] arr)

Peek at the back of arr, treating it like a queue.

queuePop
T queuePop(T[] arr)

Pop a value off the front of arr, treating it like a queue.

removeAll
size_t removeAll(T[] arr, T elem)

Remove all matching elements in an array, mutating the array. Returns the number of removed elements.

removeFirst
bool removeFirst(T[] arr, T elem)

Remove first matching element in an array, mutating the array. Returns true if the array has been modified. Cf. K[V].remove(K)

repeatOne
T[] repeatOne(T c, size_t l)

Return a new T[] of length l, filled with c.

sample
auto ref sample(T[] arr)

Select and return a random element from the array.

shift
T shift(T[] arr)

Remove the first element of arr and return it.

shift
T[] shift(T[] arr, size_t n)

Remove the n first elements of arr and return them.

shift
T[N] shift(T[] arr)
Undocumented in source. Be warned that the author may not have intended to support it.
skipUntil
T[] skipUntil(T[] source, D delim, bool orUntilEnd)

Returns the slice of source up to the first occurrence of delim, and fast-forwards source to the point after delim. If delim is not found, the behavior depends on orUntilEnd: - If orUntilEnd is false (default), it returns null and leaves source unchanged. - If orUntilEnd is true, it returns source, and then sets source to null.

slice
T[] slice(T[] arr, size_t p0, size_t p1)

Slices an array. Throws an Exception (not an Error) on out-of-bounds, even in release builds.

sliceIndex
size_t sliceIndex(T[] arr, T[] slice)

Given an array and its slice, returns the start index of the slice inside the array. The reverse operation of slicing an array.

slicesOver
bool slicesOver(const(T)[] arr, T element)

Given an array and a reference to an element, return whether the array slices over the element reference.

split1
auto split1(T value, S separator)

Like std.array.split, but always returns a non-empty array.

splitEmpty
auto splitEmpty(T value, S separator)

Like std.array.split, but returns null if val was empty.

splitWithPrefix
H[] splitWithPrefix(H haystack, S separator)

Include delimiter in result chunks as prefix

splitWithPrefixAndSuffix
S[] splitWithPrefixAndSuffix(S haystack, S prefix, S suffix)

Include delimiters in result chunks as prefix/suffix

splitWithSuffix
H[] splitWithSuffix(H haystack, S separator)

Include delimiter in result chunks as suffix

stackPeek
T stackPeek(T[] arr)

Peek at the front of arr, treating it like a stack.

stackPop
T stackPop(T[] arr)

Pop a value off the front of arr, treating it like a stack.

stackPush
void stackPush(T[] arr, T val)

Push val into arr, treating it like a stack.

staticArray
T[n] staticArray(T[n] a)
Undocumented in source. Be warned that the author may not have intended to support it.
toArray
deprecated T[] toArray(T v)
Undocumented in source. Be warned that the author may not have intended to support it.
unshift
void unshift(T[] arr, T value)

Insert elements in the front of arr.

unshift
void unshift(T[] arr, T[] value)
Undocumented in source. Be warned that the author may not have intended to support it.
vector
T[] vector(T[] a, T[] b)

Performs binary operation op on every element of a and b.

vectorAssign
T[] vectorAssign(T[] a, T[] b)

Performs in-place binary operation op on every element of a and b.

Imports

staticArray (from std.array)
public import std.array : staticArray;

std.array.staticArray polyfill

Properties

asBytes
inout(ubyte)[] asBytes [@property getter]

Return the value represented as an array of bytes.

asSlice
T[] asSlice [@property getter]

Slice a variable.

asStaticBytes
inout(ubyte)[T.sizeof] asStaticBytes [@property getter]

Return the value represented as a static array of bytes.

asUnitStaticArray
T[1] asUnitStaticArray [@property getter]

Wrap v into a static array of length 1.

bytes
deprecated inout(ubyte)[] bytes [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
bytes
deprecated inout(ubyte)[] bytes [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Structs

NormalizedArray
struct NormalizedArray(T, alias normalize)

Array with normalized comparison and hashing.

Templates

afilter
template afilter(alias pred)
Undocumented in source.
amap
template amap(alias pred)

Equivalents of array(xxx(...)).

eatUntil
deprecated template eatUntil(OnEof onEof = OnEof.throwException)
Undocumented in source.
mapNull
template mapNull(alias dg)

If arr is null, return null. Otherwise, return a non-null transformation dg over arr.

skipWhile
template skipWhile(alias pred)

Like std.algorithm.skipOver, but stops when pred(suffix) or pred(suffix[0]) returns false.

toStaticArray
template toStaticArray(size_t n)

Convert a dynamic array to a static array

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <ae@cy.md>