WaksmanUtils { private void setControlBits(int[] perm, int[][] controlBits, int rowIdx, int colIdx) { int n = perm.length; if (n == 2) { controlBits[rowIdx][colIdx] = perm[0]; return; } int[] rowI = new int[n / 2]; int[] rowO = new int[n / 2]; for (int j = 0; j < rowO.length; j++) { rowI[j] = -1; rowO[j] = -1; } int[] topPerm = new int[n / 2]; int[] bottomPerm = new int[n / 2]; int[] permInv = invert(perm); while (hasNextUnsetSwapper(rowO)) { int rowOSwIdx = nextUnsetSwapperIdx(rowO); rowO[rowOSwIdx] = 0; int firstOElIdx = topElIndexOf(rowOSwIdx); int rowOElIdx = firstOElIdx; int rowIElIdx = routeFromOutputToInput(rowOElIdx, permInv, topPerm, rowI); rowOElIdx = routeFromInputToOutput(rowIElIdx, perm, bottomPerm, rowO); while (!(rowOElIdx == firstOElIdx)) { rowIElIdx = routeFromOutputToInput(rowOElIdx, permInv, topPerm, rowI); rowOElIdx = routeFromInputToOutput(rowIElIdx, perm, bottomPerm, rowO); } } int numCols = controlBits[0].length; for (int j = 0; j < rowI.length; j++) { controlBits[rowIdx + j][colIdx] = rowI[j]; controlBits[rowIdx + j][numCols - 1 - colIdx] = rowO[j]; } setControlBits(topPerm, controlBits, rowIdx, colIdx + 1); setControlBits(bottomPerm, controlBits, rowIdx + rowI.length / 2, colIdx + 1); }  int getNumRowsRequired(int n); int getNumColsRequired(int n); boolean isPow2(int n); int[] invert(int[] p); Matrix<BigInteger> setControlBits(int[] perm);  }
@Test(expected = UnsupportedOperationException.class) public void testSetControlBits(){ WaksmanUtils util = new WaksmanUtils(); int[] controlBits = new int[]{2,3,0,1}; Matrix<BigInteger> permutationMatrix = util.setControlBits(controlBits); assertThat(permutationMatrix.getHeight(), is(2)); assertThat(permutationMatrix.getWidth(), is(controlBits.length-1)); util.setControlBits(new int[]{2,1,0}); }