-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a053222
Showing
24 changed files
with
2,331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.travis.* export-ignore | ||
.archer.* export-ignore | ||
test export-ignore | ||
*.md export-ignore | ||
LICENCE export-ignore | ||
phpcs.xml export-ignore | ||
phpunit.xml export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# composer vendor directory | ||
vendor/ | ||
|
||
#build | ||
build/ | ||
|
||
# composer | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# see http://about.travis-ci.org/docs/user/languages/php/ for more hints | ||
# example: https://github.com/travis-ci-examples/php | ||
language: php | ||
|
||
php: | ||
# aliased to a recent 7.x version | ||
- '7.0' | ||
# aliased to a recent 7.1.x version | ||
- '7.1' | ||
# aliased to a recent 7.1.x version | ||
- '7.2' | ||
# aliased to a recent hhvm version | ||
#- hhvm | ||
- nightly | ||
|
||
# This triggers builds to run on the new TravisCI infrastructure. | ||
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ | ||
sudo: false | ||
|
||
## Cache composer | ||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
matrix: | ||
fast_finish: true # Will finish as soon as a job has failed, or when the only jobs left allow failures. | ||
include: | ||
- php: '7.0' | ||
env: | ||
- 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' | ||
|
||
# execute any number of scripts before the test run, custom env's are available as variables | ||
before_script: | ||
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist | ||
|
||
# omitting "script:" will default to phpunit | ||
script: | ||
- vendor/bin/phpcs --standard=phpcs.xml | ||
- vendor/bin/phpunit --configuration phpunit.xml --coverage-text | ||
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Change Log | ||
============ | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) | ||
as it's described in the [Contributing Guide](CONTRIBUTING.md). | ||
|
||
# Proposals | ||
|
||
We do not give estimated times for completion on `Accepted` Proposals. | ||
|
||
- [Accepted][Accepted] | ||
- [Rejected][Rejected] | ||
|
||
--- | ||
## [v1.0.0][Unreleased] - Unreleased | ||
|
||
`INIT` | ||
|
||
<!-- References --> | ||
|
||
[Accepted]: https://github.com/Triun/PHP-Longest-Common-Substring/labels/Accepted | ||
[Rejected]: https://github.com/Triun/PHP-Longest-Common-Substring/labels/Rejected | ||
|
||
[Unreleased]: https://github.com/Triun/PHP-Longest-Common-Substring/compare/1.0.0...HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Contributing | ||
|
||
Before you contribute code, please make sure it conforms to the PSR-2 coding standard and that the unit tests still pass. The easiest way to contribute is to work on your own fork. | ||
|
||
If you do this, you can run the following commands to check if everything is ready to submit. | ||
|
||
## Dependencies | ||
|
||
In order to load the dependencies, you should run composer: | ||
|
||
```bash | ||
composer install | ||
``` | ||
|
||
## PSR-2 Specs | ||
|
||
This package follows the PSR-2 coding standard. | ||
|
||
- [PSR-2: Coding Style Guide] | ||
- [OPNsense PSR-2 Coding Style Guide] | ||
|
||
To test if your contribution passes the standard, you can use the command: | ||
|
||
```bash | ||
./vendor/bin/phpcs --standard=phpcs.xml | ||
``` | ||
|
||
Which should give you no output, indicating that there are no coding standard errors. | ||
|
||
## Unit testing | ||
|
||
You can write your own tests and add them to the `tests` directory. | ||
|
||
To run the test command: | ||
|
||
```bash | ||
./vendor/bin/phpunit --configuration phpunit.xml --coverage-text | ||
``` | ||
|
||
Which should give you no failures or errors. | ||
|
||
A coverage and logs will be created in the `build` directory. | ||
|
||
In order to give support to older versions, you should test it also with the lowest composer packages: | ||
|
||
```bash | ||
composer update --prefer-stable --prefer-lowest | ||
``` | ||
|
||
## Branching and pull requests | ||
|
||
As a guideline, please follow this process: | ||
|
||
1. [Fork the repository]. | ||
2. Create a topic branch for the change: | ||
- New features should branch from **develop**. | ||
- Bug fixes to existing versions should branch from **master**. | ||
- Please ensure the branch is clearly labelled as a feature or fix. | ||
3. Make the relevant changes. | ||
4. [Squash] commits if necessary. | ||
4. Submit a pull request to the **develop** branch. | ||
|
||
Please note this is a general guideline only. For more information on the | ||
branching structure please see the [git-flow cheatsheet]. | ||
|
||
<!-- References --> | ||
|
||
[PSR-2: Coding Style Guide]: http://www.php-fig.org/psr/psr-2/ | ||
[OPNsense PSR-2 Coding Style Guide]: https://docs.opnsense.org/development/guidelines/psr2.html | ||
[Fork the repository]: https://help.github.com/articles/fork-a-repo | ||
[git-flow cheatsheet]: http://danielkummer.github.com/git-flow-cheatsheet/ | ||
[Squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Triun | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
PHP - Longest Common Substring | ||
============================== | ||
|
||
PHP implementation of an algorithm to solve the `longest common substring` problem. | ||
|
||
[![Latest Version on Packagist][ico-version]][link-packagist] | ||
[![Pre Release Version on Packagist][ico-pre-release]][link-packagist] | ||
[![Latest Unstable Version][ico-unstable]][link-packagist] | ||
[![Build Status][ico-travis]][link-travis] | ||
[![Coverage status][ico-codecov]][link-codecov] | ||
[![Total Downloads][ico-downloads]][link-downloads] | ||
[![The most recent stable version is 2.0.0][ico-semver]][link-semver] | ||
[![Software License][ico-license]](LICENSE.md) | ||
|
||
# About | ||
|
||
*PHP-Longest-Common-Subsequence* is a PHP implementation of an algorithm to solve the 'longest common substring' problem. | ||
|
||
From [Wikipedia - Longest common substring problem](https://en.wikipedia.org/wiki/Longest_common_substring_problem): | ||
|
||
> In computer science, the longest common substring problem is to find the longest string (or strings) that is a | ||
> substring (or are substrings) of two or more strings. | ||
# Installation | ||
|
||
Require [triun/longest-common-substring package](https://packagist.org/packages/triun/longest-common-substring) with [composer](http://getcomposer.org/) | ||
using the following command: | ||
|
||
```bash | ||
composer require triun/longest-common-substring | ||
``` | ||
|
||
# Usage | ||
|
||
## Solver | ||
|
||
```php | ||
use Triun\LongestCommonSubstring\Solver; | ||
|
||
$solver = new Solver(); | ||
|
||
$stringA = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'; | ||
$stringB = '56789AB56789ABCDE56789ABCDE56789AB56789A123456789A'; | ||
|
||
// calculates the LCSubstring to be '123456789A' | ||
$result = $solver->solve($stringA, $stringB); | ||
``` | ||
|
||
## Matches solver | ||
|
||
```php | ||
use Triun\LongestCommonSubstring\Solver; | ||
|
||
$solver = new Solver(); | ||
|
||
$stringA = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'; | ||
$stringB = '56789AB56789ABCDE56789ABCDE56789AB56789A123456789A'; | ||
|
||
$matches = $matchSolver->solve($stringA, $stringB); | ||
|
||
// calculates the LCSubstring to be '123456789A' | ||
$result = "$matches"; | ||
``` | ||
|
||
|
||
But also can give you the rest of the results which has the same length: | ||
|
||
```php | ||
var_dump($matches->values()); | ||
``` | ||
|
||
``` | ||
array:12 [ | ||
0 => "123456789A" | ||
1 => "56789ABCDE" | ||
2 => "56789ABCDE" | ||
3 => "123456789A" | ||
4 => "56789ABCDE" | ||
5 => "56789ABCDE" | ||
6 => "123456789A" | ||
7 => "56789ABCDE" | ||
8 => "56789ABCDE" | ||
9 => "123456789A" | ||
10 => "56789ABCDE" | ||
11 => "56789ABCDE" | ||
] | ||
``` | ||
|
||
You can use `unique` to skip duplicated values: | ||
|
||
```php | ||
var_dump($matches->unique()); | ||
``` | ||
|
||
``` | ||
array:2 [ | ||
0 => "123456789A" | ||
1 => "56789ABCDE" | ||
] | ||
``` | ||
|
||
Or even more information about the matches, like the input strings indexes: | ||
|
||
```php | ||
var_dump($matches->values()); | ||
``` | ||
|
||
``` | ||
array:12 [ | ||
0 => array:3 [ | ||
"value" => "123456789A" | ||
"length" => 10 | ||
"indexes" => array:2 [ | ||
0 => 1 | ||
1 => 40 | ||
] | ||
] | ||
1 => array:3 [ | ||
"value" => "56789ABCDE" | ||
"length" => 10 | ||
"indexes" => array:2 [ | ||
0 => 5 | ||
1 => 7 | ||
] | ||
] | ||
2 => array:3 [ | ||
"value" => "56789ABCDE" | ||
"length" => 10 | ||
"indexes" => array:2 [ | ||
0 => 5 | ||
1 => 17 | ||
] | ||
] | ||
... | ||
] | ||
``` | ||
|
||
# Issues | ||
|
||
Bug reports and feature requests can be submitted on the | ||
[Github Issue Tracker](https://github.com/Triun/PHP-Longest-Common-Substring/issues). | ||
|
||
# Contributing | ||
|
||
See [CONTRIBUTING.md](CONTRIBUTING.md) for information. | ||
|
||
# License | ||
|
||
This repository is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) | ||
|
||
<!-- References --> | ||
|
||
[ico-version]: https://img.shields.io/packagist/v/triun/longest-common-substring.svg | ||
[ico-pre-release]: https://img.shields.io/packagist/vpre/triun/longest-common-substring.svg | ||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square | ||
[ico-travis]: https://travis-ci.org/Triun/PHP-Longest-Common-Substring.svg?branch=master | ||
[ico-code-quality]: https://img.shields.io/scrutinizer/g/triun/longest-common-substring.svg?style=flat-square | ||
[ico-downloads]: https://img.shields.io/packagist/dt/triun/longest-common-substring.svg?style=flat-square | ||
[ico-unstable]: https://poser.pugx.org/triun/longest-common-substring/v/unstable | ||
[ico-coveralls]: https://coveralls.io/repos/github/Triun/PHP-Longest-Common-Substring/badge.svg?branch=master "Current test coverage for the develop branch" | ||
[ico-codecov]: https://codecov.io/gh/Triun/PHP-Longest-Common-Substring/branch/master/graph/badge.svg | ||
[ico-semver]: http://img.shields.io/:semver-2.0.0-brightgreen.svg "This project uses semantic versioning" | ||
|
||
[link-packagist]: https://packagist.org/packages/triun/longest-common-substring | ||
[link-travis]: https://travis-ci.org/Triun/PHP-Longest-Common-Substring | ||
[link-downloads]: https://packagist.org/packages/triun/longest-common-substring | ||
[link-author]: https://github.com/Triun | ||
[link-coveralls]: https://coveralls.io/github/Triun/PHP-Longest-Common-Substring?branch=master | ||
[link-codecov]: https://codecov.io/gh/Triun/PHP-Longest-Common-Substring | ||
[link-semver]: http://semver.org/ |
Oops, something went wrong.