Documentation of 'cc.redberry.core.combinatorics.IntCombinationsGenerator' Java class
IntCombinationsGenerator
cc.redberry.core.combinatorics

Class IntCombinationsGenerator

  • All Implemented Interfaces:
    IntCombinatorialPort, OutputPort<int[]>, java.lang.Iterable<int[]>, java.util.Iterator<int[]>


    public final class IntCombinationsGenerator
    extends IntCombinatorialGenerator
    implements IntCombinatorialPort
    This class represents an 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. So, if it is needed not only to obtain the information from next(), but also save the result, it is necessary to clone the returned array.

    Since:
    1.0
    • Constructor Detail

      • IntCombinationsGenerator

        public IntCombinationsGenerator(int n,
                                        int k)
    • Method Detail

      • take

        public int[] take()
        Description copied from interface: IntCombinatorialPort
        Calculates and returns the next combination or null, if no more combinations exist.
        Specified by:
        take in interface IntCombinatorialPort
        Specified by:
        take in interface OutputPort<int[]>
        Returns:
        the next combination or null, if no more combinations exist
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<int[]>
      • next

        public int[] next()
        Specified by:
        next in interface java.util.Iterator<int[]>
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<int[]>
        Throws:
        java.lang.UnsupportedOperationException - always

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.