Class IntCombinations

  • All Implemented Interfaces:
    CombinatorialIterator<int[]>, java.io.Serializable, java.lang.Iterable<int[]>, java.util.Iterator<int[]>

    public final class IntCombinations
    extends IntCombinatorialIterator
    Iterator over all unordered combinations (i.e. [0,1] and [1,0] are considered as same, so only [0,1] will appear in the sequence) of k numbers, which can be chosen from the set of n numbers (0,1,2,...,n). The total number of such combinations is a binomial coefficient n!/(k!(n-k)!). Each returned array is sorted.

    The iterator is implemented such that each next combination will be calculated only on the invocation of method next().

    Note: method next() returns the same reference on each invocation.

    Since:
    1.0
    See Also:
    IntCombinationsWithPermutations, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int[] combination  
      private int k  
      private int n  
      private boolean onFirst  
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      IntCombinations​(int n, int k)
      Constructs the iterator with the desired n and k
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int[] current()
      Returns the reference on the current iteration element.
      boolean hasNext()  
      private boolean isLast()  
      int[] next()  
      void remove()  
      void reset()
      Resets the iteration
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • combination

        final int[] combination
      • n

        private final int n
      • k

        private final int k
      • onFirst

        private boolean onFirst
    • Constructor Detail

      • IntCombinations

        public IntCombinations​(int n,
                               int k)
        Constructs the iterator with the desired n and k
    • Method Detail

      • hasNext

        public boolean hasNext()
      • reset

        public void reset()
        Description copied from interface: CombinatorialIterator
        Resets the iteration
      • isLast

        private boolean isLast()
      • next

        public int[] next()
      • remove

        public void remove()
        Throws:
        java.lang.UnsupportedOperationException - always
      • current

        public int[] current()
        Description copied from interface: CombinatorialIterator
        Returns the reference on the current iteration element.
        Returns:
        the reference on the current iteration element