public static int[] lengthsOfCycles(final byte[] permutation) {
IntArrayList sizes = new IntArrayList();
BitArray seen = new BitArray(permutation.length);
int counter = 0;
while (counter < permutation.length) {
int start = seen.nextZeroBit(0);
if (permutation[start] == start) {
++counter;
seen.set(start);
continue;
}