/** * Finds the next mapping from the current state. * * @return the next state (or null if none) */ private int[] findNext() { while (map()); if (state.size() == state.nMax()) return state.mapping(); return null; }
/** * 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(); }