/** * Create a stream for the provided state. * * @param state the state to stream over */ StateStream(final State state) { this.state = state; this.stack = new CandidateStack(state.nMax()); this.next = state.nMax() == 0 || state.mMax() == 0 ? null : findNext(); // first-mapping }
/** * Progress the state-machine - the function return false when a mapping is * found on the mapping is done. * * @return the state is partial */ private boolean map() { // backtrack - we've tried all possible n or m, remove the last mapping if ((n == state.nMax() || m == state.mMax()) && !stack.empty()) state.remove(n = stack.popN(), m = stack.popM()); while ((m = state.nextM(n, m)) < state.mMax()) { if (state.add(n, m)) { stack.push(n, m); n = state.nextN(-1); m = -1; return n < state.nMax(); } } return state.size() > 0 || m < state.mMax(); }