Class IntegerPartitionGenerator

  • All Implemented Interfaces:
    Generator<int[]>, Serializable

    public class IntegerPartitionGenerator
    extends Object
    implements Generator<int[]>
    Integer partition generator, derived from fast multipartite number partition generator.
    Author:
    Tilman Neumann
    See Also:
    Serialized Form
    • Constructor Detail

      • IntegerPartitionGenerator

        public IntegerPartitionGenerator​(int n)
        Complete constructor for a generator of the partitions of n
        Parameters:
        n -
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Generator<int[]>
        Returns:
        true if there is another partition
      • next

        public int[] next()
        Compute the next partition of the input. The result is an array of the parts, which is much faster than creating Multisets. The parts of a partition are sorted biggest part first; the order in which partitions appear is undefined.
        Specified by:
        next in interface Generator<int[]>
        Returns:
        next partition
      • partitionsOf

        public static SortedSet<IntegerPartition> partitionsOf​(int n)
        Computes the partitions of the given number. This is much slower than iterating over the results of the next() method and may give memory problems for big arguments, but the result is correctly ordered and has nice String output.
        Parameters:
        n -
        Returns:
        partitions = SortedSet, partition = IntegerPartition_Additive, part = Integer
      • main

        public static void main​(String[] args)
        Test
        Parameters:
        args - ignored