com.datumbox.framework.core.mathematics.discrete
Class Combinatorics
- java.lang.Object
-
- com.datumbox.framework.core.mathematics.discrete.Combinatorics
-
public class Combinatorics extends java.lang.ObjectUtility class for combinations and permutations.
-
-
Constructor Summary
Constructors Constructor and Description Combinatorics()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static <T> java.util.Set<java.util.Set<T>>combinations(java.util.Set<T> elements, int subsetSize)Returns all the possible combinations of the set.static <T> java.util.Iterator<T[]>combinationsIterator(T[] elements, int subsetSize)Fast and memory efficient way to return an iterator with all the possible combinations of an array.static <T> java.util.stream.Stream<java.util.Set<T>>combinationsStream(java.util.Set<T> elements, int subsetSize)Returns all the possible combinations of the set in a stream.static <T> java.util.Collection<java.util.List<T>>permutations(java.util.Collection<T> elements)Returns the permutations of a collection.
-
-
-
Method Detail
-
permutations
public static <T> java.util.Collection<java.util.List<T>> permutations(java.util.Collection<T> elements)
Returns the permutations of a collection. Ported from: http://stackoverflow.com/questions/10503392/java-code-for-permutations-of-a-list-of-numbers- Type Parameters:
T-- Parameters:
elements-- Returns:
-
combinations
public static <T> java.util.Set<java.util.Set<T>> combinations(java.util.Set<T> elements, int subsetSize)Returns all the possible combinations of the set.- Type Parameters:
T-- Parameters:
elements-subsetSize-- Returns:
-
combinationsStream
public static <T> java.util.stream.Stream<java.util.Set<T>> combinationsStream(java.util.Set<T> elements, int subsetSize)Returns all the possible combinations of the set in a stream. Heavily Modified code: http://codereview.stackexchange.com/questions/26854/recursive-method-to-return-a-set-of-all-combinations- Type Parameters:
T-- Parameters:
elements-subsetSize-- Returns:
-
combinationsIterator
public static <T> java.util.Iterator<T[]> combinationsIterator(T[] elements, int subsetSize)Fast and memory efficient way to return an iterator with all the possible combinations of an array. Heavily Modified code: http://hmkcode.com/calculate-find-all-possible-combinations-of-an-array-using-java/- Type Parameters:
T-- Parameters:
elements-subsetSize-- Returns:
-
-
DataMelt 3.0 © DataMelt by jWork.ORG