Documentation of 'org.matheclipse.core.generic.combinatoric.KPartitionsIterable' Java class
KPartitionsIterable
org.matheclipse.core.generic.combinatoric

Class KPartitionsIterable

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


    public class KPartitionsIterable
    extends java.lang.Object
    implements java.util.Iterator<int[]>, java.lang.Iterable<int[]>
    This class returns the indexes for partitioning a list of N elements.
    Usage pattern:
     final KPartitionsIterable iter = new KPartitionsIterable(n, k);
     for (int[] partitionsIndex : iter) {
       ...
     }
     
    Example: KPartitionsIterable(3,5) gives the following sequences [0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4]
    If you interpret these integer lists as indexes for a list {a,b,c,d,e} which should be partitioned into 3 parts the results are:
    {{{a},{b},{c,d,e}}, {{a},{b,c},{d,e}}, {{a},{b,c,d},{e}}, {{a,b},{c},{d,e}}, {{a,b},{c,d},{e}}, {{a,b,c},{d},{e}}}

    See Wikipedia - Partition of a set
    • Constructor Summary

      Constructors 
      Constructor and Description
      KPartitionsIterable(int length, int parts) 
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean hasNext() 
      java.util.Iterator<int[]> iterator() 
      int[] next()
      Get the index array for the next partition.
      void remove() 
      void reset() 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • KPartitionsIterable

        public KPartitionsIterable(int length,
                                   int parts)
    • Method Detail

      • reset

        public final void reset()
      • next

        public int[] next()
        Get the index array for the next partition.
        Specified by:
        next in interface java.util.Iterator<int[]>
        Returns:
        null if no further index array could be generated
      • hasNext

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

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

        public java.util.Iterator<int[]> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<int[]>

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.