MapSetVisitor

Allows executing a deterministic algorithm over all states in a given MapSet. If a variable is not queried by the algorithm, states for all variations of that variable are processed in one iteration.

Constructors

this
this(Set set)
Undocumented in source.

Members

Aliases

Set
alias Set = MapSet!(A, V)

Underlying MapSet.

Functions

get
V get(A name)

Algorithm interface - get a value by name

inject
void inject(A name, V[] values)

Inject a variable and values to iterate over. The variable must not have been resolved yet.

injectiveTransform
void injectiveTransform(A name, void delegate(ref V value) fun)

Apply a function over every possible value of the given variable, without resolving it (unless it's already resolved). The function is assumed to be injective (does not produce duplicate outputs for distinct inputs).

next
bool next()

Returns true if there are more states to iterate over, otherwise returns false

put
void put(A name, V value)

Algorithm interface - set a value by name

reset
void reset()

Resets iteration to the beginning. Equivalent to but faster than constructing a new MapSetVisitor instance (visitor = MapSetVisitor(visitor.set)).

transform
void transform(A name, void delegate(ref V value) fun)

Apply a function over every possible value of the given variable, without resolving it (unless it's already resolved).

Properties

currentSubset
Set currentSubset [@property getter]

Peek at the subset the algorithm is currently working with.

Structs

Var
struct Var

Internal state.

Variables

resolvedValues
V[A] resolvedValues;
Undocumented in source.
set
Set set;

Underlying MapSet.

singularValues
V[A] singularValues;
Undocumented in source.
stack
Var[] stack;
Undocumented in source.
stackPos
size_t stackPos;
Undocumented in source.

Examples

An algorithm which divides two numbers. When the divisor is zero, we don't even query the dividend, therefore processing all dividends in one iteration.

alias M = MapSet!(string, int);
M m = M.unitSet
	.cartesianProduct("divisor" , [0, 1, 2])
	.cartesianProduct("dividend", [0, 1, 2]);
assert(m.count == 9);

auto v = MapSetVisitor!(string, int)(m);
M results;
int iterations;
while (v.next())
{
	iterations++;
	auto divisor = v.get("divisor");
	if (divisor == 0)
		continue;
	auto dividend = v.get("dividend");
	v.put("quotient", dividend / divisor);
	results = results.merge(v.currentSubset);
}

assert(iterations == 7); // 1 for division by zero + 3 for division by one + 3 for division by two
assert(results.get("divisor", 2).get("dividend", 2).all("quotient") == [1]);
assert(results.get("divisor", 0).count == 0);

Meta