Package cc.redberry.combinatorics
Class Combinatorics
java.lang.Object
cc.redberry.combinatorics.Combinatorics
This class provides factory and utility methods for combinatorics infrastructure.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interfaceprivate static final class(package private) static final class(package private) static final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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.
-
Field Details
-
arrayComparator
-
-
Constructor Details
-
Combinatorics
private Combinatorics()
-
-
Method Details
-
combinations
Iterator over all k-combinations from {code n}.- Parameters:
n- combination lengthk- the total
-
combinationsWithPermutations
Iterator over all k-combinations with permutations from {code n}.- Parameters:
n- combination lengthk- the total
-
permutations
Iterator over all permutations of the specified length -
compositions
Iterator over all compositions ofintegerintonPartitions- Parameters:
integer- the sumnPartitions- number of partitions- See Also:
-
distinctTuples
Iterator over all distinct N-tuples, which can be chosen fromNspecified sets of integers.- Parameters:
sets- array of sets of integers- See Also:
-
deepClone
private static int[][] deepClone(int[][] sets) -
tuples
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:
-
map
-
permutations
Iterator over all permutations of the specified array -
combinations
Iterator over all k-combinations from the specified array -
combinationsWithPermutations
Iterator over all k-combinations with permutations from the specified array -
map
-
indices
private static int[] indices(int length) -
distinctTuples
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:
-
tuples
Iterator over all N-tuples, which can be chosen fromNspecified sets of integers.- Parameters:
sets- array of sets of integers- See Also:
-