Package cc.redberry.combinatorics
Class Combinatorics
- java.lang.Object
-
- cc.redberry.combinatorics.Combinatorics
-
public final class Combinatorics extends java.lang.ObjectThis class provides factory and utility methods for combinatorics infrastructure.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceCombinatorics.ArrayFactory<T>private static classCombinatorics.GenericFactory<T>(package private) static classCombinatorics.TIterator<T>(package private) static classCombinatorics.TTIterator<T>
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.Comparator<int[]>arrayComparator
-
Constructor Summary
Constructors Modifier Constructor Description privateCombinatorics()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CombinatorialIterator<int[]>combinations(int n, int k)Iterator over all k-combinations from {code n}.static <T> CombinatorialIterator<T[]>combinations(T[] input, int k)Iterator over all k-combinations from the specified arraystatic CombinatorialIterator<int[]>combinationsWithPermutations(int n, int k)Iterator over all k-combinations with permutations from {code n}.static <T> CombinatorialIterator<T[]>combinationsWithPermutations(T[] input, int k)Iterator over all k-combinations with permutations from the specified arraystatic CombinatorialIterator<int[]>compositions(int integer, int nPartitions)Iterator over all compositions ofintegerintonPartitionsprivate static int[][]deepClone(int[][] sets)static CombinatorialIterator<int[]>distinctTuples(int[]... sets)Iterator over all distinct N-tuples, which can be chosen fromNspecified sets of integers.static <T> CombinatorialIterator<T[]>distinctTuples(T[]... sets)Iterator over all N-tuples of elements at different positions, which can be chosen fromNspecified sets of elements.private static int[]indices(int length)private static <T> T[]map(T[][] arrays, int[] indices, Combinatorics.ArrayFactory<T> factory)private static <T> T[]map(T[] array, int[] indices, Combinatorics.ArrayFactory<T> factory)static CombinatorialIterator<int[]>permutations(int n)Iterator over all permutations of the specified lengthstatic <T> CombinatorialIterator<T[]>permutations(T[] input)Iterator over all permutations of the specified arraystatic CombinatorialIterator<int[]>tuples(int... bounds)Iterator over all N-tuples (not necessary to be distinct), which can be chosen fromNarrays of integers of the form arrayi = [0, 1, 2, ..., Ki]static <T> CombinatorialIterator<T[]>tuples(T[]... sets)Iterator over all N-tuples, which can be chosen fromNspecified sets of integers.
-
-
-
Method Detail
-
combinations
public static CombinatorialIterator<int[]> combinations(int n, int k)
Iterator over all k-combinations from {code n}.- Parameters:
n- combination lengthk- the total
-
combinationsWithPermutations
public static CombinatorialIterator<int[]> combinationsWithPermutations(int n, int k)
Iterator over all k-combinations with permutations from {code n}.- Parameters:
n- combination lengthk- the total
-
permutations
public static CombinatorialIterator<int[]> permutations(int n)
Iterator over all permutations of the specified length
-
compositions
public static CombinatorialIterator<int[]> compositions(int integer, int nPartitions)
Iterator over all compositions ofintegerintonPartitions- Parameters:
integer- the sumnPartitions- number of partitions- See Also:
IntCompositions
-
distinctTuples
public static CombinatorialIterator<int[]> distinctTuples(int[]... sets)
Iterator over all distinct N-tuples, which can be chosen fromNspecified sets of integers.- Parameters:
sets- array of sets of integers- See Also:
IntDistinctTuples
-
deepClone
private static int[][] deepClone(int[][] sets)
-
tuples
public static CombinatorialIterator<int[]> tuples(int... bounds)
Iterator over all N-tuples (not necessary to be distinct), which can be chosen fromNarrays of integers of the form arrayi = [0, 1, 2, ..., Ki]- Parameters:
bounds- the bounds on the tuple elements- See Also:
IntDistinctTuples
-
map
private static <T> T[] map(T[] array, int[] indices, Combinatorics.ArrayFactory<T> factory)
-
permutations
public static <T> CombinatorialIterator<T[]> permutations(T[] input)
Iterator over all permutations of the specified array
-
combinations
public static <T> CombinatorialIterator<T[]> combinations(T[] input, int k)
Iterator over all k-combinations from the specified array
-
combinationsWithPermutations
public static <T> CombinatorialIterator<T[]> combinationsWithPermutations(T[] input, int k)
Iterator over all k-combinations with permutations from the specified array
-
map
private static <T> T[] map(T[][] arrays, int[] indices, Combinatorics.ArrayFactory<T> factory)
-
indices
private static int[] indices(int length)
-
distinctTuples
public static <T> CombinatorialIterator<T[]> distinctTuples(T[]... sets)
Iterator over all N-tuples of elements at different positions, which can be chosen fromNspecified sets of elements.- Parameters:
sets- array of sets of integers- See Also:
IntDistinctTuples
-
tuples
public static <T> CombinatorialIterator<T[]> tuples(T[]... sets)
Iterator over all N-tuples, which can be chosen fromNspecified sets of integers.- Parameters:
sets- array of sets of integers- See Also:
IntDistinctTuples
-
-