/* Generates all matrixes whose rows and columns are taken * from the prefix trees passed at construction time. * * After construction, each successful call to next * produces a representation of a new matrix. */ class MatrixGenerator { private Tree rowTree; // prefix tree of rows private Tree colTree; // prefix tree of columns private int nrows,ncols; // Shape of matrix private int K; // Entries of matrix are in 0...K-1 // The search algorithm works by trial extension of a region // of overlapping partial rows and columns. The two arrays // below represent that region by locating the Node for // each partial row and column. private Node rowNodes[]; private Node colNodes[]; // more search variables: current(Row/Col/Branch) // these variables give the cell we are trying to fill, // and the value we are trying to fill it with. private int currentRow, currentCol, currentBranch; // if done is true then there are no more matricies private boolean done; // These arrays represent a matrix. (The arrays point // to lists of indexes of lines that form the matrix.) // After a successful call to next(), the caller // can examine these arrays to extract the matrix. Link rowLinks[]; Link colLinks[]; /* Constructor */ MatrixGenerator(Tree rowTree,Tree colTree) { ncols = rowTree.length(); currentCol=0; nrows = colTree.length(); currentRow=0; K = rowTree.arity(); currentBranch=0; done = false; // initialize row search arrays rowNodes = new Node[nrows]; rowLinks = new Link[nrows]; for(int r=0;r