/** * Create a permutation using the given permutation vector. * * @param perm the permutation vector */ public Permutation(int[] perm) { if (!isPermutation(perm)) { throw new IllegalArgumentException( "array is not a permutation vector"); } this.perm = IntUtils.clone(perm); }
/** * Create a permutation using the given permutation vector. * * @param perm the permutation vector */ public Permutation(int[] perm) { if (!isPermutation(perm)) { throw new IllegalArgumentException( "array is not a permutation vector"); } this.perm = IntUtils.clone(perm); }
/** * Create a permutation from an encoded permutation. * * @param enc the encoded permutation */ public Permutation(byte[] enc) { if (enc.length <= 4) { throw new IllegalArgumentException("invalid encoding"); } int n = LittleEndianConversions.OS2IP(enc, 0); int size = IntegerFunctions.ceilLog256(n - 1); if (enc.length != 4 + n * size) { throw new IllegalArgumentException("invalid encoding"); } perm = new int[n]; for (int i = 0; i < n; i++) { perm[i] = LittleEndianConversions.OS2IP(enc, 4 + i * size, size); } if (!isPermutation(perm)) { throw new IllegalArgumentException("invalid encoding"); } }
/** * Create a permutation from an encoded permutation. * * @param enc the encoded permutation */ public Permutation(byte[] enc) { if (enc.length <= 4) { throw new IllegalArgumentException("invalid encoding"); } int n = LittleEndianConversions.OS2IP(enc, 0); int size = IntegerFunctions.ceilLog256(n - 1); if (enc.length != 4 + n * size) { throw new IllegalArgumentException("invalid encoding"); } perm = new int[n]; for (int i = 0; i < n; i++) { perm[i] = LittleEndianConversions.OS2IP(enc, 4 + i * size, size); } if (!isPermutation(perm)) { throw new IllegalArgumentException("invalid encoding"); } }