Class Permutation


  • public class Permutation
    extends java.lang.Object
    This class implements permutations of the set {0,1,...,n-1} for some given n > 0, i.e., ordered sequences containing each number m (0 <= m < n) once and only once.
    • Constructor Summary

      Constructors 
      Constructor Description
      Permutation​(byte[] enc)
      Create a permutation from an encoded permutation.
      Permutation​(int n)
      Create the identity permutation of the given size.
      Permutation​(int[] perm)
      Create a permutation using the given permutation vector.
      Permutation​(int n, java.security.SecureRandom sr)
      Create a random permutation of the given size.
    • Constructor Detail

      • Permutation

        public Permutation​(int n)
        Create the identity permutation of the given size.
        Parameters:
        n - the size of the permutation
      • Permutation

        public Permutation​(int[] perm)
        Create a permutation using the given permutation vector.
        Parameters:
        perm - the permutation vector
      • Permutation

        public Permutation​(byte[] enc)
        Create a permutation from an encoded permutation.
        Parameters:
        enc - the encoded permutation
      • Permutation

        public Permutation​(int n,
                           java.security.SecureRandom sr)
        Create a random permutation of the given size.
        Parameters:
        n - the size of the permutation
        sr - the source of randomness
    • Method Detail

      • getEncoded

        public byte[] getEncoded()
        Encode this permutation as byte array.
        Returns:
        the encoded permutation
      • getVector

        public int[] getVector()
        Returns:
        the permutation vector (perm(0),perm(1),...,perm(n-1))
      • computeInverse

        public Permutation computeInverse()
        Compute the inverse permutation P-1.
        Returns:
        this-1
      • rightMultiply

        public Permutation rightMultiply​(Permutation p)
        Compute the product of this permutation and another permutation.
        Parameters:
        p - the other permutation
        Returns:
        this * p
      • equals

        public boolean equals​(java.lang.Object other)
        checks if given object is equal to this permutation.

        The method returns false whenever the given object is not permutation.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - - permutation
        Returns:
        true or false
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        a human readable form of the permutation
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code of this permutation