Class IntCombinations

java.lang.Object
cc.redberry.combinatorics.IntCombinatorialIterator
cc.redberry.combinatorics.IntCombinations
All Implemented Interfaces:
CombinatorialIterator<int[]>, Serializable, Iterable<int[]>, 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:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • combination

      final int[] combination
    • n

      private final int n
    • k

      private final int k
    • onFirst

      private boolean onFirst
  • Constructor Details

    • IntCombinations

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

    • 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:
      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