dalicious.algorithm

Some additional alogorithm functions.

Members

Functions

backtracking
T[] backtracking(T[] candidates, T[] solution = [])

Find an optimal solution using backtracking.

cmpLexicographically
int cmpLexicographically(T a, T b)

Compare a and b lexicographically by applying each fun to them. For unary functions compares fun(a) < fun(b).

filterInPlace
Array filterInPlace(auto ref Array array)

Returns array filtered in-place.

first
ElementType!Range first(Range range)

Get the first element in range assuming it to be non-empty.

last
ElementType!Range last(Range range)

Get the last element in range assuming it to be non-empty.

orderLexicographically
bool orderLexicographically(T a, T b)

Order a and b lexicographically by applying each fun to them. For unary functions compares fun(a) < fun(b).

replaceInPlace
Array replaceInPlace(auto ref Array array, E needle, E replacement)

Replaces the first occurrence of needle by replacement in array if present. Modifies array.

sliceBy
auto sliceBy(Array array)

Slices an input array into slices of equivalent adjacent elements. In other languages this is often called partitionBy, groupBy or sliceWhen.

sliceUntil
Array sliceUntil(Array haystack, Needle needle, OpenRight openRight = Yes.openRight)
Array sliceUntil(Array haystack, OpenRight openRight = Yes.openRight)

Return the prefix of haystack where pred is not satisfied.

uniqInPlace
Array uniqInPlace(auto ref Array array)

Returns array uniqified in-place.

Templates

staticPredSwitch
template staticPredSwitch(T...)

Returns one of a collection of expressions based on the value of the switch expression.

Meta

License

Subject to the terms of the MIT license, as written in the included LICENSE file.

Authors

Arne Ludwig <arne.ludwig@posteo.de>