Function
Static Public Summary | ||
public |
* diagonal(A: Iterable, B: Iterable): IterableIterator Computes the product of two iterables in a way that allows for one or both of them to be infinite (in contrast with product). |
|
public |
Computes the product of the iterables given as first parameter. |
Static Private Summary | ||
private |
Algorithm used by product to compute the product of one or more iterables from pools of symbols. |
Static Public
public * diagonal(A: Iterable, B: Iterable): IterableIterator source
import diagonal from '@set-theory/cartesian-product/src/diagonal.js'
Computes the product of two iterables in a way that allows for one or both of them to be infinite (in contrast with product). Although the output iterator may be infinite, it is guaranteed that each value of the product is located at some finite position in the output iterator.
If one of the two inputs has finite size N, it is guaranteed that memory usage never exceeds O(N) values. If both inputs have infinite size, then memory usage grows proportionally to the square root of the number of output pairs.
Params:
Name | Type | Attribute | Description |
A | Iterable | The first iterable. |
|
B | Iterable | The second iterable. |
Return:
IterableIterator |
Example:
// returns [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 1 ] ]
list( diagonal( range( 2 ) , range( 2 ) ) ) ;
public product(iterables: Iterable<Iterable>, repeat: number): IterableIterator source
import product from '@set-theory/cartesian-product/src/product.js'
Computes the product of the iterables given as first parameter. The second
parameter is an integer that tells how many times the list of iterables
given as input should be concatenated to itself before computing the
product. This second parameter is optional and its default value is
1
.
Params:
Name | Type | Attribute | Description |
iterables | Iterable<Iterable> | The input iterables. |
|
repeat | number | The number of times to cycle through the input iterables. |
Return:
IterableIterator |
Example:
// Ax Ay Bx By Cx Cy Dx Dy
product(['ABCD', 'xy']) ;
// 000 001 010 011 100 101 110 111
product([range(2)], 3) ;
Static Private
private * _product(pools: Array<Iterable>, i: number, n: number): IterableIterator source
import _product from '@set-theory/cartesian-product/src/_product.js'
Algorithm used by product to compute the product of one or more iterables from pools of symbols.
Return:
IterableIterator |
Example:
// Ax Ay Bx By Cx Cy Dx Dy
_product(['xy', 'ABCD'], 0 , 2) ;
// 000 001 010 011 100 101 110 111
_product([[0,1],[0,1],[0,1]], 0 , 3) ;