CombinationsGenerator class
Generates all possible combinations from a matrix of parameters.
Signature
export declare class CombinationsGenerator
Remarks
This class computes the Cartesian product of multiple parameter arrays, producing all possible combinations of parameter values using a memory-efficient generator pattern. It uses a recursive algorithm to systematically explore all combinations one at a time.
The generation process:
- Takes arrays of parameter names (keys) and their corresponding value arrays.
- Recursively iterates through each parameter, selecting one value at a time.
- Yields complete combinations one at a time without storing them all in memory.
- Backtracks to explore other value combinations.
Example usage:
const generator = new CombinationsGenerator({
matrixKeys: ['arch', 'optimize'],
matrixValues: [['x64', 'arm'], ['speed', 'size']],
log
});
for (const combo of generator.generate()) {
// Process one combination at a time without storing all in memory
// Results:
// { arch: 'x64', optimize: 'speed' }
// { arch: 'x64', optimize: 'size' }
// { arch: 'arm', optimize: 'speed' }
// { arch: 'arm', optimize: 'size' }
await processConfiguration(combo);
}
Constructors
|
Constructor |
Modifiers |
Description |
|---|---|---|
|
(constructor)({ matrixKeys, matrixValues, maxCombinations, log, }, input) |
Constructs a combinations generator instance. |
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
|
Logger |
The logger instance for output and diagnostics. | |
|
|
string[] |
The array of parameter names. | |
|
|
string[][] |
The array of value arrays for each parameter. | |
|
|
number |
The maximum number of combinations allowed. |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
|
Recursively generates combinations as a generator, yielding one at a time. | |
|
Generates combinations one at a time using a generator pattern. |
Generated via tsdoc2docusaurus 1.3.2 by API Extractor/Documenter 7.57.2.