zawiszaty/sorted-linked-list
最新稳定版本:1.0.0
Composer 安装命令:
composer require zawiszaty/sorted-linked-list
包简介
Sorted linked list library with strict type safety for int or string values.
README 文档
README
Strictly typed, always-sorted singly linked list for PHP.
Overview
This library provides a SortedLinkedList data structure that:
- keeps values in ascending order after every write operation,
- supports one type per instance:
intorstring, - allows duplicates with stable order for equal values,
- exposes a small and predictable API.
Project specification:
requirements.mdHLD.md
Requirements
- PHP
^8.2 - Composer
Installation
composer install
Quick Start
<?php declare(strict_types=1); use Zawiszaty\SortedLinkedList\SortedLinkedList; $list = SortedLinkedList::forInt(); $list->addAll([3, 1, 2, 2]); echo $list . PHP_EOL; // [1, 2, 2, 3] echo $list->first() . PHP_EOL; // 1 echo $list->last() . PHP_EOL; // 3
String mode:
$list = SortedLinkedList::forString(); $list->addAll(['pear', 'apple', 'banana']); // ['apple', 'banana', 'pear']
Custom comparator:
$list = SortedLinkedList::forInt( static fn (int $a, int $b): int => $b <=> $a ); $list->addAll([1, 3, 2]); // [3, 2, 1]
Public API
SortedLinkedList::forInt(?callable $comparator = null): selfSortedLinkedList::forString(?callable $comparator = null): selfadd(int|string $value): voidaddAll(iterable<int|string> $values): voidremove(int|string $value): boolremoveAll(int|string $value): intremoveAt(int $index): voidcontains(int|string $value): boolget(int $index): int|stringfirst(): int|stringlast(): int|stringclear(): voidtoArray(): arraycount(): intisEmpty(): boolgetIterator(): Traversable__toString(): string
Exceptions
TypeMismatchExceptionIndexOutOfBoundsExceptionEmptyListException
Example Script
Run the example:
php examples/demo.php
Performance Benchmarking
Run a quick terminal benchmark:
php benchmarks/performance.php
Generate machine-readable results:
php benchmarks/performance.php --json > benchmarks/current.json
Render a human-readable report from JSON:
php benchmarks/render-report.php benchmarks/current.json
Check performance regression against the baseline (30% threshold by default):
php benchmarks/check-regression.php benchmarks/current.json benchmarks/baseline.json
Use a custom regression threshold (example 20%):
php benchmarks/check-regression.php benchmarks/current.json benchmarks/baseline.json 0.20
Quality Gates
This repository is configured with:
- PHPUnit
- PHPStan (max level)
- Psalm
- PHP CS Fixer
- Infection (mutation testing)
Current mutation gate is configured in infection.json5:
minMsi: 80.0minCoveredMsi: 80.0
Development Commands
composer test
composer stan
composer psalm
composer cs:check
XDEBUG_MODE=coverage composer infection
CI Pipeline
GitHub Actions workflow (.github/workflows/ci.yml) runs in this order:
build- static analysis in parallel:
phpstan,cs-check,psalm - in parallel after static analysis:
tests(PHP matrix) andmutation-testing
Project Layout
src/- library source codetests/- PHPUnit testsexamples/- runnable usage demorequirements.md- requirements specificationHLD.md- high-level design
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2026-02-19