davidvarney/sortedlinkedlist
最新稳定版本:1.0.0
Composer 安装命令:
composer require davidvarney/sortedlinkedlist
包简介
A PHP library providing a sorted linked list for int or string values.
README 文档
README
A tiny PHP library that provides a sorted singly-linked list which accepts either ints or strings (but not both). The list keeps values in sorted order as values are added.
Installation
Install with Composer:
composer require davidvarney/sortedlinkedlist
For development (to run tests):
composer install
Basic usage
use DavidVarney\SortedLinkedList\SortedLinkedList; $list = new SortedLinkedList(); $list->add(5); $list->add(1); $list->add(3); // returns [1, 3, 5] print_r($list->toArray()); // string join with default glue ", " echo $list->toString(); // "1, 3, 5" // type information echo $list->getType(); // "int" $list->clear(); $list->add('banana'); $list->add('apple'); echo $list->toString('|'); // "apple|banana"
Notes:
- The list enforces type consistency: once you add an int the list only accepts ints; same for strings.
- Attempting to add the other type throws an InvalidArgumentException.
API
add(int|string $value): void— Insert a value in sorted order.remove(int|string $value): bool— Remove a value; returns true if removed.toArray(): array— Return the list as an array of values.toString(string $glue = ', '): string— Return a joined string of values.contains(int|string $value): bool— Check presence of a value.isEmpty(): bool— Check if the list is empty.clear(): void— Clear the list and reset the stored type.getType(): ?string— Returns'int','string', ornullfor empty list.
Running tests
This project uses PHPUnit (configured in phpunit.xml). Run the tests with the vendored PHPUnit binary:
./vendor/bin/phpunit
For a more readable output use testdox:
./vendor/bin/phpunit --testdox
Test coverage
This repository doesn't include a coverage tool by default, but you can generate coverage with Xdebug or PCOV installed and PHPUnit's --coverage-html option. Example (requires Xdebug enabled):
./vendor/bin/phpunit --coverage-html coverage
# open coverage/index.html in your browser
CI / PHPStan
This repository runs PHPStan via GitHub Actions on push and pull_request to main.
To run PHPStan locally after installing dev dependencies:
./vendor/bin/phpstan analyse -c phpstan.neon
License
MIT
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-01