baygin/php-search-algorithms
最新稳定版本:1.1.0
Composer 安装命令:
composer require baygin/php-search-algorithms
包简介
The search algorithms implementation for the php arrays that usable as a composer package
README 文档
README
The search algorithm implementation in PHP 8 to find the value with the query as fast.
Usage
Install
Git Clone
git clone https://github.com/baygin/php-search-algorithms.git
Composer
composer require baygin/php-search-algorithms
Binary Search
Array
$array = []; for ($index = 0; $index < 100 * 10000; $index++) { $array[] = $index + 1; } $search = new BinarySearch(); $search->setCompareCallback(fn ($current, $searchValue) => $current === $searchValue) ->setDirectionCallback(fn ($current, $searchValue) => $current < $searchValue) ->setArray($array) ->setSearchValue(98589) ->search(); $foundIndex = $search->getFoundIndex(); $foundValue = $search->getFoundValue();
Arrays in array
$array = []; for ($index = 0; $index < 100 * 10000; $index++) { $array[] = [ "id" => $index + 1, "first" => "Baris {$index}", "last" => "Manco {$index}", ]; } $search = new BinarySearch(); $search->setCompareCallback(fn ($current, $searchValue) => $current["id"] === $searchValue) ->setDirectionCallback(fn ($current, $searchValue) => $current["id"] < $searchValue) ->setArray($array) ->setSearchValue(81300) ->search(); $foundIndex = $search->getFoundIndex(); $foundValue = $search->getFoundValue();
Objects in array
$array = []; for ($index = 0; $index < 100 * 10000; $index++) { $array[] = (object) [ "id" => $index + 1, "first" => "Baris {$index}", "last" => "Manco {$index}", ]; } $search = new BinarySearch(); $search->setCompareCallback(fn ($current, $searchValue) => $current->id === $searchValue) ->setDirectionCallback(fn ($current, $searchValue) => $current->id < $searchValue) ->setArray($array) ->setSearchValue(81300) ->search(); $foundIndex = $search->getFoundIndex(); $foundValue = $search->getFoundValue();
Tests
composer test
Contributing
If you want to contribute to the development of this library, you can open an issue or submit a pull request.
License
Licensed under the GPL3. See LICENSE for more information.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2023-04-13