Skip to content

Commit 6569726

Browse files
committed
Init
0 parents  commit 6569726

File tree

11 files changed

+2965
-0
lines changed

11 files changed

+2965
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
.phpunit.result.cache

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# The Search Algorithms Implemantation in PHP 8
2+
3+
The search algorithm implementation in PHP 8 to find the value with the query as fast.
4+
5+
# Usage
6+
7+
## Binary Search
8+
9+
### Array
10+
11+
```php
12+
$array = [];
13+
14+
for ($index = 0; $index < 100 * 10000; $index++) {
15+
$array[] = $index + 1;
16+
}
17+
18+
$search = new BinarySearch();
19+
20+
$search ->setCompareCallback(fn ($current, $searchValue) => $current === $searchValue)
21+
->setDirectionCallback(fn ($current, $searchValue) => $current < $searchValue)
22+
->setArray($array)
23+
->setSearchValue(98589)
24+
->search();
25+
26+
$foundIndex = $search->getFoundIndex();
27+
$foundValue = $search->getFoundValue();
28+
```
29+
30+
### Arrays in array
31+
32+
```php
33+
$array = [];
34+
35+
for ($index = 0; $index < 100 * 10000; $index++) {
36+
$array[] = [
37+
"id" => $index + 1,
38+
"first" => "Baris {$index}",
39+
"last" => "Manco {$index}",
40+
];
41+
}
42+
43+
$search = new BinarySearch();
44+
45+
$search->setCompareCallback(fn ($current, $searchValue) => $current["id"] === $searchValue)
46+
->setDirectionCallback(fn ($current, $searchValue) => $current["id"] < $searchValue)
47+
->setType("arrays in array")
48+
->setArray($array)
49+
->setSearchValue(81300)
50+
->search();
51+
52+
$foundIndex = $search->getFoundIndex();
53+
$foundValue = $search->getFoundValue();
54+
```
55+
56+
### Objects in array
57+
58+
```php
59+
60+
$array = [];
61+
62+
for ($index = 0; $index < 100 * 10000; $index++) {
63+
$array[] = (object) [
64+
"id" => $index + 1,
65+
"first" => "Baris {$index}",
66+
"last" => "Manco {$index}",
67+
];
68+
}
69+
70+
$search = new BinarySearch();
71+
$search
72+
->setCompareCallback(fn ($current, $searchValue) => $current->id === $searchValue)
73+
->setDirectionCallback(fn ($current, $searchValue) => $current->id < $searchValue)
74+
->setType("objects in array")
75+
->setArray($array)
76+
->setSearchValue(81300)
77+
->search();
78+
79+
$foundIndex = $search->getFoundIndex();
80+
$foundValue = $search->getFoundValue();
81+
```
82+
83+
## Tests
84+
85+
```bash
86+
composer test
87+
```
88+
89+
## Contributing
90+
91+
If you want to contribute to the development of this library, you can open an issue or submit a pull request.
92+
93+
# License
94+
95+
Licensed under the GPL3. See <a href="https://github.com/baygin/php-search-algorithms/blob/master/LICENSE"> LICENSE </a> for more information.

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "baygin/php-search-algorithms",
3+
"description": "The search algorithms implementation for the php arrays that usable as a composer package",
4+
"keywords": [
5+
"php",
6+
"array",
7+
"binary-search",
8+
"search-algorithm"
9+
],
10+
"type": "library",
11+
"license": "GPL-3.0-or-later",
12+
"authors": [
13+
{
14+
"name": "baygin",
15+
"role": "Developer"
16+
}
17+
],
18+
"require": {
19+
"php": ">=8.2"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Baygin\\SearchAlgorithm\\": "src"
24+
}
25+
},
26+
"version": "1.0.0",
27+
"require-dev": {
28+
"phpunit/phpunit": "^9"
29+
},
30+
"scripts": {
31+
"test": "phpunit"
32+
}
33+
}

0 commit comments

Comments
 (0)