Class IntCompositions

java.lang.Object
cc.redberry.combinatorics.IntCompositions
All Implemented Interfaces:
IntCombinatorialPort, Serializable

public final class IntCompositions extends Object implements IntCombinatorialPort
Iterator over all compositions of specified integer into N parts.

Implementation note: the description of the algorithm can be found here https://stackoverflow.com/a/6609080/946635

Since:
2.0
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • integer

      private final int integer
    • nCompositions

      private final int nCompositions
    • generator

      private final IntCombinations generator
    • array

      private int[] array
  • Constructor Details

    • IntCompositions

      public IntCompositions(int integer, int nCompositions)
  • Method Details

    • reset

      public void reset()
      Description copied from interface: IntCombinatorialPort
      Resets the iteration
      Specified by:
      reset in interface IntCombinatorialPort
    • getReference

      public int[] getReference()
      Description copied from interface: IntCombinatorialPort
      Returns the reference to the current iteration element
      Specified by:
      getReference in interface IntCombinatorialPort
      Returns:
      the reference to the current iteration element
    • 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
      Returns:
      the next combination or null, if no more combinations exist