th3n3rd / cartesian-product
Memory efficient Cartesian Product implementation
Installs: 83 587
Dependents: 3
Suggesters: 0
Security: 0
Stars: 13
Watchers: 1
Forks: 5
Open Issues: 2
Requires
- php: >=5.3.3
Requires (Dev)
- devster/ubench: ~1.1
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2024-12-21 19:06:24 UTC
README
Memory efficient Cartesian Product implementation.
It uses iterators in order to store only a specific tuple at time being able to compute even large combinations without affecting the memory footprint.
Install
Via Composer
$ composer require th3n3rd/cartesian-product
Usage
use Nerd\CartesianProduct\CartesianProduct; $cartesianProduct = new CartesianProduct(); $cartesianProduct ->appendSet(array('a', 'b', 'c')) ->appendSet(array('d', 'e')) ->appendSet(array('f', 'g', 'h')) ->appendSet(array('i', 'j')) ->appendSet(array('k', 'l')) ->appendSet(array('m', 'n')) ->appendSet(array('o')) ->appendSet(array('p')) ->appendSet(array('q', 'r', 's', 't')) ->appendSet(array('u', 'v', 'w')) ->appendSet(array('x', 'y')) ->appendSet(array('z')) ; foreach ($cartesianProduct as $index => $product) { printf("[%s] (%s)\n", $index, implode(',', $product)); } // or (not recommended) $result = $cartesianProduct->compute(); foreach ($result as $index => $product) { printf("[%s] (%s)\n", $index, implode(',', $product)); }
Testing
$ phpunit
License
The MIT License (MIT). Please see License File for more information.