/** * Merges pairs of rows by making them identical and marking them as equivalent. For each merged * pair, also merges each pair of not yet merged images by the same generator, and so on * recursively, until no more pairs need to be merged. * * @param Q a list of row pairs to merge. * @param P the row equivalence classes (modified by this method). * @return the number of individual merges performed. */ private int performIdentifications(final LinkedList Q, final IntPartition P) { int count = 0; while (Q.size() > 0) { final IntPair pair = (IntPair) Q.removeFirst(); final int a = P.find(pair.getFirst()); final int b = P.find(pair.getSecond()); if (a == b) { continue; } P.unite(a, b); ++count; final int row_a[] = (int[]) this.table.get(a); final int row_b[] = (int[]) this.table.get(b); for (int g = 0; g < this.ngens; ++g) { final int ag = row_a[g]; final int bg = row_b[g]; if (ag == 0) { row_a[g] = bg; } else if (bg == 0) { row_b[g] = ag; } else if (!P.areEquivalent(ag, bg)) { Q.addLast(new IntPair(ag, bg)); } } this.table.set(b, row_a); } return count; }