The OpenD Programming Language

CombinationsRepeat

Lazy Forward range of combinations with repeats. It always generates combinations with repeats from 0 to n - 1, use indexedRoR to map it to your range.

Generating a new combination with repeats is in O(k), the number of combinations with repeats is binomial(n, k).

Constructors

this
this(size_t n, T[] state)

state should have the length of repeat

Members

Aliases

DeepElement
alias DeepElement = T

Functions

popFront
void popFront()
empty
bool empty [@property getter]

Input range primitives

Properties

front
Slice!(const(T)*) front [@property getter]
length
size_t length [@property getter]

Input range primitives

save
CombinationsRepeat save [@property getter]

Forward range primitive. Allocates using GC.

shape
size_t[2] shape [@property getter]

Examples

import mir.ndslice.fuse;
import mir.ndslice.topology: iota;
import std.string: representation;

assert(iota(2).combinationsRepeat.fuse == [[0], [1]]);
assert(iota(2).combinationsRepeat(2).fuse == [[0, 0], [0, 1], [1, 1]]);
assert(iota(3).combinationsRepeat(2).fuse == [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]]);
assert("AB"d.representation.combinationsRepeat(2).fuse == ["AA"d, "AB"d,  "BB"d]);
import mir.algorithm.iteration: equal;
import mir.ndslice.slice: sliced;
import mir.ndslice.topology: iota;

import std.experimental.allocator.mallocator;
auto alloc = Mallocator.instance;

static immutable expected3r1 = [
    0, 
    1, 
    2];
auto r = iota(3);
auto rc = alloc.makeCombinationsRepeat(r.length, 1);
assert(expected3r1.sliced(3, 1).equal(rc.indexedRoR(r)));
alloc.dispose(rc);

See Also

Meta