xi / algorithm
通用算法
dev-master
2013-11-08 12:24 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-14 13:50:42 UTC
README
各种算法的集合。
Luhn 算法
用法
use Xi\Algorithm\Luhn; $luhn = new Luhn(); $luhn->generate(123); // 1230
拓扑排序
对一个无向图进行排序,使得如果节点 X 指向节点 Y,则 Y 在列表中先于 X 出现。 了解更多。
基本上,它对于解决依赖图非常有用。
用法
// A description of a graph: $edges = array( 'B' => array('C', 'D'), // Node B points to nodes C and D 'A' => array('B'), // Node A points to node B 'C' => array('D'), // Node C points to node D ); $nodesSorted = \Xi\Algorithm\TopologicalSort::apply($edges); // $nodesSorted is now array('D', 'C', 'B', 'A')
运行测试
不存在对其他库的依赖,但为了生成自动加载器,首先运行
composer.phar install --dev
然后使用以下命令运行测试
phpunit -c tests