|
2 | 2 |
|
3 | 3 | *An implementation of the 'longest common subsequence' algorithm for PHP.* |
4 | 4 |
|
5 | | -[![Build Status]](http://travis-ci.org/ezzatron/php-lcs) |
6 | | -[![Test Coverage]](http://ezzatron.com/php-lcs/artifacts/tests/coverage/) |
| 5 | +[![The most recent stable version is 2.0.0][version-image]][Semantic versioning] |
| 6 | +[![Current build status image][build-image]][Current build status] |
| 7 | +[![Current coverage status image][coverage-image]][Current coverage status] |
7 | 8 |
|
8 | | -## Installation |
| 9 | +## Installation and documentation |
9 | 10 |
|
10 | | -Available as [Composer](http://getcomposer.org/) package |
11 | | -[ezzatron/php-lcs](https://packagist.org/packages/ezzatron/php-lcs). |
| 11 | +- Available as [Composer] package [eloquent/lcs]. |
| 12 | +- [API documentation] available. |
12 | 13 |
|
13 | 14 | ## What is PHP-LCS? |
14 | 15 |
|
15 | | -PHP-LCS is a PHP implementation of an algorithm to solve the 'longest common |
| 16 | +*PHP-LCS* is a PHP implementation of an algorithm to solve the 'longest common |
16 | 17 | subsequence' problem. |
17 | 18 |
|
18 | | -From [Wikipedia](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem): |
| 19 | +From [Wikipedia - longest common subsequence problem]: |
19 | 20 |
|
20 | 21 | > The **longest common subsequence (LCS) problem** is to find the longest |
21 | | -> [subsequence](http://en.wikipedia.org/wiki/Subsequence) common to all |
22 | | -> sequences in a set of sequences (often just two). Note that subsequence is |
23 | | -> different from a substring, see |
24 | | -> [substring vs. subsequence](http://en.wikipedia.org/wiki/Subsequence#Substring_vs._subsequence). |
25 | | -> It is a classic [computer science](http://en.wikipedia.org/wiki/Computer_science) |
26 | | -> problem, the basis of [file comparison](http://en.wikipedia.org/wiki/File_comparison) |
27 | | -> programs such as [diff](http://en.wikipedia.org/wiki/Diff), and has |
28 | | -> applications in [bioinformatics](http://en.wikipedia.org/wiki/Bioinformatics). |
| 22 | +> [subsequence] common to all sequences in a set of sequences (often just two). |
| 23 | +> Note that subsequence is different from a substring, see [substring vs. |
| 24 | +> subsequence]. It is a classic [computer science] problem, the basis of [file |
| 25 | +> comparison] programs such as [diff], and has applications in [bioinformatics]. |
29 | 26 |
|
30 | 27 | ## Usage |
31 | 28 |
|
32 | 29 | ```php |
33 | | -use Ezzatron\LCS\LCSSolver; |
| 30 | +use Eloquent\Lcs\LcsSolver; |
34 | 31 |
|
35 | | -$solver = new LCSSolver; |
| 32 | +$solver = new LcsSolver; |
36 | 33 |
|
37 | | -$left = array( |
38 | | - 'B', |
39 | | - 'A', |
40 | | - 'N', |
41 | | - 'A', |
42 | | - 'N', |
43 | | - 'A', |
44 | | -); |
45 | | -$right = array( |
46 | | - 'A', |
47 | | - 'T', |
48 | | - 'A', |
49 | | - 'N', |
50 | | - 'A', |
51 | | -); |
52 | | -$expectedLCS = array( |
53 | | - 'A', |
54 | | - 'A', |
55 | | - 'N', |
56 | | - 'A', |
57 | | -); |
| 34 | +$sequenceA = array('B', 'A', 'N', 'A', 'N', 'A'); |
| 35 | +$sequenceB = array('A', 'T', 'A', 'N', 'A'); |
58 | 36 |
|
59 | | -$LCS = $solver->longestCommonSubsequence( |
60 | | - $left, |
61 | | - $right |
62 | | -); |
| 37 | +// calculates the LCS to be array('A', 'A', 'N', 'A') |
| 38 | +$lcs = $solver->longestCommonSubsequence($sequenceA, $sequenceB); |
| 39 | +``` |
| 40 | + |
| 41 | +Elements in sequences can be anything. By default, sequence members are compared |
| 42 | +using the `===` operator. To customize this comparison, simply construct the |
| 43 | +solver with a custom comparator, like so: |
63 | 44 |
|
64 | | -if ($LCS === $expectedLCS) { |
65 | | - echo 'LCS solver is working.'; |
66 | | -} else { |
67 | | - echo 'LCS solver is not working.'; |
68 | | -} |
69 | | -// the above outputs 'LCS solver is working.' |
| 45 | +```php |
| 46 | +use Eloquent\Lcs\LcsSolver; |
| 47 | + |
| 48 | +$solver = new LcsSolver( |
| 49 | + function ($left, $right) { |
| 50 | + // return true if $left and $right are equal |
| 51 | + } |
| 52 | +); |
70 | 53 | ``` |
71 | 54 |
|
72 | | -<!-- references --> |
73 | | -[Build Status]: https://raw.github.com/ezzatron/php-lcs/gh-pages/artifacts/images/icecave/regular/build-status.png |
74 | | -[Test Coverage]: https://raw.github.com/ezzatron/php-lcs/gh-pages/artifacts/images/icecave/regular/coverage.png |
| 55 | +<!-- References --> |
| 56 | + |
| 57 | +[bioinformatics]: http://en.wikipedia.org/wiki/Bioinformatics |
| 58 | +[computer science]: http://en.wikipedia.org/wiki/Computer_science |
| 59 | +[diff]: http://en.wikipedia.org/wiki/Diff |
| 60 | +[file comparison]: http://en.wikipedia.org/wiki/File_comparison |
| 61 | +[subsequence]: http://en.wikipedia.org/wiki/Subsequence |
| 62 | +[substring vs. subsequence]: http://en.wikipedia.org/wiki/Subsequence#Substring_vs._subsequence |
| 63 | +[Wikipedia - longest common subsequence problem]: http://en.wikipedia.org/wiki/Longest_common_subsequence_problem |
| 64 | + |
| 65 | +[API documentation]: http://lqnt.co/php-lcs/artifacts/documentation/api/ |
| 66 | +[Composer]: http://getcomposer.org/ |
| 67 | +[build-image]: http://img.shields.io/travis/eloquent/php-lcs/develop.svg "Current build status for the develop branch" |
| 68 | +[Current build status]: https://travis-ci.org/eloquent/php-lcs |
| 69 | +[coverage-image]: http://img.shields.io/coveralls/eloquent/php-lcs/develop.svg "Current test coverage for the develop branch" |
| 70 | +[Current coverage status]: https://coveralls.io/r/eloquent/php-lcs |
| 71 | +[eloquent/lcs]: https://packagist.org/packages/eloquent/lcs |
| 72 | +[Semantic versioning]: http://semver.org/ |
| 73 | +[version-image]: http://img.shields.io/:semver-2.0.0-brightgreen.svg "This project uses semantic versioning" |
0 commit comments