org.matheclipse.core.generic.combinatoric
Class KPartitionsIterable
- java.lang.Object
-
- org.matheclipse.core.generic.combinatoric.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 booleanhasNext()java.util.Iterator<int[]>iterator()int[]next()Get the index array for the next partition.voidremove()voidreset()
-
-
-
Method Detail
-
reset
public final void reset()
-
next
public int[] next()
Get the index array for the next partition.- Specified by:
nextin interfacejava.util.Iterator<int[]>- Returns:
nullif no further index array could be generated
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfacejava.util.Iterator<int[]>
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<int[]>
-
iterator
public java.util.Iterator<int[]> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<int[]>
-
-
DMelt 3.0 © DataMelt by jWork.ORG