eloquent / lcs
An implementation of the 'longest common subsequence' algorithm for PHP.
Installs: 319 029
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 4
Forks: 3
Open Issues: 2
Requires
- php: >=5.3
Requires (Dev)
- icecave/archer: ~1
This package is auto-updated.
Last update: 2023-08-08 04:19:24 UTC
README
No longer maintained
This package is no longer maintained. See this statement for more info.
PHP-LCS
An implementation of the 'longest common subsequence' algorithm for PHP.
Installation and documentation
- Available as Composer package eloquent/lcs.
- API documentation available.
What is PHP-LCS?
PHP-LCS is a PHP implementation of an algorithm to solve the 'longest common subsequence' problem.
From Wikipedia - longest common subsequence problem:
The longest common subsequence (LCS) problem is to find the longest subsequence common to all sequences in a set of sequences (often just two). Note that subsequence is different from a substring, see substring vs. subsequence. It is a classic computer science problem, the basis of file comparison programs such as diff, and has applications in bioinformatics.
Usage
use Eloquent\Lcs\LcsSolver; $solver = new LcsSolver; $sequenceA = array('B', 'A', 'N', 'A', 'N', 'A'); $sequenceB = array('A', 'T', 'A', 'N', 'A'); // calculates the LCS to be array('A', 'A', 'N', 'A') $lcs = $solver->longestCommonSubsequence($sequenceA, $sequenceB);
Elements in sequences can be anything. By default, sequence members are compared
using the ===
operator. To customize this comparison, simply construct the
solver with a custom comparator, like so:
use Eloquent\Lcs\LcsSolver; $solver = new LcsSolver( function ($left, $right) { // return true if $left and $right are equal } );