th3n3rd / cartesian-product
内存高效的笛卡尔积实现
v0.3.0
2015-05-30 08:42 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- devster/ubench: ~1.1
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2024-09-14 17:31:57 UTC
README
内存高效的笛卡尔积实现。
它使用迭代器来存储特定的时间戳,能够计算甚至大型组合而不影响内存占用。
安装
通过Composer
$ composer require th3n3rd/cartesian-product
用法
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)); }
测试
$ phpunit
许可证
MIT许可证(MIT)。更多信息请见许可证文件。