Package dev.nm.misc.algorithm
Class CartesianProduct<T>
- java.lang.Object
-
- dev.nm.misc.algorithm.CartesianProduct<T>
-
public class CartesianProduct<T> extends Object implements Iterable<List<T>>
The Cartesian product can be generalized to the n-ary Cartesian product over n sets X1, ..., Xn. \[ X_1\times\cdots\times X_n = \{(x_1, \ldots, x_n): x_i \in X_i \} \] It is a set of n-tuples.- See Also:
- Wikipedia: n-ary product
-
-
Constructor Summary
Constructors Constructor Description CartesianProduct(T[]... sets)
Construct anIterable
of all combinations of arrays, taking one element from each array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterator<List<T>>
iterator()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
CartesianProduct
public CartesianProduct(T[]... sets)
Construct anIterable
of all combinations of arrays, taking one element from each array. For example, suppose we have two arrays:{1, 2} {3, 4, 5}
The possible combinations are:{1, 3} {1, 4} {1, 5} {2, 3} {2, 4} {2, 5}
- Parameters:
sets
- arrays of elements
-
-