The OpenD Programming Language

mir.algorithm.iteration

This module contains generic iteration algorithms.

Function

Function NameDescription
allChecks if all elements satisfy to a predicate.
anyChecks if at least one element satisfy to a predicate.
cmpCompares two slices.
countCounts elements in a slices according to a predicate.
eachIterates elements.
eachLowerIterates lower triangle of matrix.
eachOnBorderIterates elementes on tensors borders and corners.
eachUploPairIterates upper and lower pairs of elements in square matrix.
eachUpperIterates upper triangle of matrix.
equalCompares two slices for equality.
filterFilters elements in a range or an ndslice.
findFinds backward index.
findIndexFinds index.
foldAccumulates all elements (different parameter order than reduce).
isSymmetricChecks if the matrix is symmetric.
maxIndexFinds index of the maximum.
maxPosFinds backward index of the maximum.
minIndexFinds index of the minimum.
minmaxIndexFinds indices of the minimum and the maximum.
minmaxPosFinds backward indices of the minimum and the maximum.
minPosFinds backward index of the minimum.
nBitsToCountСount bits until set bit count is reached.
reduceAccumulates all elements.
ChequerChequer color selector to work with each .
uniqIterates over the unique elements in a range or an ndslice, which is assumed sorted.

Transform function is represented by $(REF_ALTTEXT $(TT map), map, mir, ndslice, topology)$(NBSP) .

All operators are suitable to change slices using ref argument qualification in a function declaration. Note, that string lambdas in Mir are auto ref functions.

Members

Enums

Chequer
enum Chequer

Chequer color selector to work with each

Functions

maxLength
size_t maxLength(S s)
nBitsToCount
sizediff_t nBitsToCount(Slice!(FieldIterator!(BitField!(Field, I))) bitSlice, size_t count)
sizediff_t nBitsToCount(Slice!(RetroIterator!(FieldIterator!(BitField!(Field, I)))) bitSlice, size_t count)

Сount bits until set bit count is reached. Works with ndslices created with mir.ndslice.topology.bitwise, mir.ndslice.allocation.bitSlice.

retroNBitsToCount
sizediff_t retroNBitsToCount(Slice!(FieldIterator!(BitField!(Field, I))) bitSlice, size_t count)
sizediff_t retroNBitsToCount(Slice!(RetroIterator!(FieldIterator!(BitField!(Field, I)))) bitSlice, size_t count)

Сount bits starting from the end until set bit count is reached. Works with ndslices created with mir.ndslice.topology.bitwise, mir.ndslice.allocation.bitSlice.

Structs

Filter
struct Filter(alias pred, Range)

Implements the higher order filter function. The predicate is passed to mir.functional.naryFun, and can either accept a string, or any callable that can be executed via pred(element).

Uniq
struct Uniq(alias pred, Range)

Authros: Andrei Alexandrescu (original Phobos code), Ilia Ki (betterC rework)

Templates

all
template all(alias pred = "a")

Checks if all of the elements verify pred.

any
template any(alias pred = "a")

Like find, but only returns whether or not the search was successful.

cmp
template cmp(alias pred = "a < b")

Performs three-way recursive lexicographical comparison on two slices according to predicate pred. Iterating sl1 and sl2 in lockstep, cmp compares each N-1 dimensional element e1 of sl1 with the corresponding element e2 in sl2 recursively. If one of the slices has been finished,cmp returns a negative value if sl1 has fewer elements than sl2, a positive value if sl1 has more elements than sl2, and 0 if the ranges have the same number of elements.

count
template count(alias fun)

Counts elements in slices according to the fun.

each
template each(alias fun)

The call each!(fun)(slice1, ..., sliceN) evaluates fun for each set of elements x1, ..., xN in slice1, ..., sliceN respectively.

eachLower
template eachLower(alias fun)

The call eachLower!(fun)(slice1, ..., sliceN) evaluates fun on the lower triangle in slice1, ..., sliceN respectively.

eachOnBorder
template eachOnBorder(alias fun)

The call each!(fun)(slice1, ..., sliceN) evaluates fun for each set of elements x1, ..., xN in the borders of slice1, ..., sliceN respectively.

eachUploPair
template eachUploPair(alias fun, bool includeDiagonal = false)

The call eachUploPair!(fun)(matrix) evaluates fun for each pair (matrix[j, i], matrix[i, j]), for i <= j (default) or i < j (if includeDiagonal is false).

eachUpper
template eachUpper(alias fun)

The call eachUpper!(fun)(slice1, ..., sliceN) evaluates fun on the upper triangle in slice1, ..., sliceN, respectively.

equal
template equal(alias pred = "a == b")

Compares two or more slices for equality, as defined by predicate pred.

filter
template filter(alias pred = "a")

Implements the higher order filter function. The predicate is passed to mir.functional.naryFun, and can either accept a string, or any callable that can be executed via pred(element).

find
template find(alias pred)

Finds a backward index such that pred(slices[0].backward(index), ..., slices[$-1].backward(index)) is true.

findIndex
template findIndex(alias pred)

Finds an index such that pred(slices[0][index], ..., slices[$-1][index]) is true.

fold
template fold(alias fun)

Implements the homonym function (also known as accumulate, compress, inject, or foldl) present in various programming languages of functional flavor. The call fold!(fun)(slice, seed) first assigns seed to an internal variable result, also called the accumulator. Then, for each element x in slice, result = fun(result, x) gets evaluated. Finally, result is returned.

isSymmetric
template isSymmetric(alias fun = "a == b")

Checks if the matrix is symmetric.

maxIndex
template maxIndex(alias pred = "a < b")

Finds an index such that slice[index] is minimal(maximal).

maxPos
template maxPos(alias pred = "a < b")

Finds a backward index such that slice.backward(index) is minimal(maximal).

minIndex
template minIndex(alias pred = "a < b")

Finds an index such that slice[index] is minimal(maximal).

minPos
template minPos(alias pred = "a < b")

Finds a backward index such that slice.backward(index) is minimal(maximal).

minmaxIndex
template minmaxIndex(alias pred = "a < b")

Finds a backward indices such that slice[indices[0]] is minimal and slice[indices[1]] is maximal elements in the slice.

minmaxPos
template minmaxPos(alias pred = "a < b")

Finds a positions (ndslices) such that position[0].first is minimal and position[1].first is maximal elements in the slice.

rcfilter
template rcfilter(alias pred = "a", alias map = "a")

Implements the higher order filter and map function. The predicate and map functions are passed to mir.functional.naryFun, and can either accept a string, or any callable that can be executed via pred(element) and map(element).

reduce
template reduce(alias fun)

Implements the homonym function (also known as accumulate, compress, inject, or fold) present in various programming languages of functional flavor. The call reduce!(fun)(seed, slice1, ..., sliceN) first assigns seed to an internal variable result, also called the accumulator. Then, for each set of element x1, ..., xN in slice1, ..., sliceN, result = fun(result, x1, ..., xN) gets evaluated. Finally, result is returned.

uniq
template uniq(alias pred = "a == b")

Lazily iterates unique consecutive elements of the given range (functionality akin to the _uniq system utility). Equivalence of elements is assessed by using the predicate pred, by default "a == b". The predicate is passed to mir.functional.nary, and can either accept a string, or any callable that can be executed via pred(element, element). If the given range is bidirectional, uniq also yields a std,range,primitives.

Meta

Authors

Ilia Ki, John Michael Hall, Andrei Alexandrescu (original Phobos code)

, Ilia Ki (Mir & BetterC rework).