vpinti/sorted-linked-list
Composer 安装命令:
composer require vpinti/sorted-linked-list
包简介
A blazing fast, type-safe sorted linked list library for PHP. Supports automatic sorting, integer and string values, and modern PHP features.
README 文档
README
A blazing fast, type-safe, and fully tested sorted linked list library for PHP. Supports both integer and string values, with automatic sorting in ascending or descending order. Designed for performance, maintainability, and extensibility.
Features
- Automatic sorting (ascending/descending)
- Type safety: only one type per list (int or string)
- Fast insert, delete, contains, clear, and iteration Internal sorting logic (no external comparator needed)
- Simple, modern API
Installation
Install via Composer:
composer require vpinti/sorted-linked-list
Usage
use Vpinti\SortedLinkedList\SortedLinkedList; use Vpinti\SortedLinkedList\Enum\SortOrder; $list = new SortedLinkedList(SortOrder::ASC); $list->insert(5); $list->insert(2); $list->insert(8); $list->insert(1); // Get sorted values as array $values = $list->toArray(); // [1, 2, 5, 8] // Check if a value exists $list->contains(5); // true // Remove a value $list->delete(2); // Iterate foreach ($list as $value) { echo $value . PHP_EOL; } // Clear the list $list->clear(); // Use with strings $stringList = new SortedLinkedList(SortOrder::DESC); $stringList->insert('banana'); $stringList->insert('apple'); $stringList->insert('pear'); // $stringList->toArray(); // ['pear', 'banana', 'apple']
API
SortedLinkedList
__construct(SortOrder $order = SortOrder::ASC)insert(int|string $value): voiddelete(int|string $value): boolcontains(int|string $value): boolclear(): voidtoArray(): arraycount(): int__toString(): string- Iterator support (
foreach)
Extensibility
Sorting logic is handled internally by the SortedLinkedList class. Custom comparators are not required or supported in this version.
Contributing
Pull requests and stars are welcome! For major changes, please open an issue first to discuss what you would like to change.
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-21