定制 jast99/sorted-linked-list 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jast99/sorted-linked-list

Composer 安装命令:

composer require jast99/sorted-linked-list

包简介

SortedLinkedList

README 文档

README

A PHP library providing a sorted linked list that keeps values in order. It can hold int or string values, but not both at the same time.

Requires PHP 8.2+.

Installation

composer require jast99/sorted-linked-list

Usage

Creating a list

use JaSt99\SortedLinkedList\SortedLinkedList;

$integers = SortedLinkedList::ofIntegers();
$strings = SortedLinkedList::ofStrings();

Inserting values

Values are automatically inserted in sorted order:

$list = SortedLinkedList::ofIntegers();
$list->insert(5);
$list->insert(1);
$list->insert(3);

$list->toArray(); // [1, 3, 5]

Removing values

Returns true if the value was found and removed, false otherwise. If duplicates exist, only the first occurrence is removed.

$list->remove(3);  // true
$list->remove(99); // false

Checking for values

$list->contains(5);  // true
$list->contains(99); // false

Accessing first and last element

$list->first(); // smallest value
$list->last();  // largest value

Both methods throw EmptyListException when the list is empty.

Count and emptiness

$list->count();   // number of elements
$list->isEmpty(); // true if empty
count($list);     // works too (Countable interface)

Iteration

The list implements IteratorAggregate, so you can use foreach:

foreach ($list as $value) {
    echo $value . PHP_EOL;
}

Converting to array and string

$list->toArray();        // [1, 3, 5]
$list->toString();       // '1, 3, 5'
$list->toString(';');    // '1;3;5'
$list->toString(' | ');  // '1 | 3 | 5'

Custom comparator

By default, values are sorted using PHP's native <=> operator. You can provide a custom comparator:

// Case-insensitive string sorting
$list = SortedLinkedList::ofStrings(strcasecmp(...));
$list->insert('Banana');
$list->insert('apple');
$list->toArray(); // ['apple', 'Banana']

// Reverse integer sorting
$list = SortedLinkedList::ofIntegers(fn(int $a, int $b): int => $b <=> $a);
$list->insert(1);
$list->insert(3);
$list->toArray(); // [3, 1]

Type safety

The list enforces type consistency both at static analysis level (PHPStan generics) and at runtime:

$list = SortedLinkedList::ofIntegers();
$list->insert('foo'); // throws ListTypeMismatchException

Development

# Run tests
vendor/bin/phpunit

# Run static analysis
vendor/bin/phpstan analyse

# Check coding standard
vendor/bin/phpcs

License

MIT

jast99/sorted-linked-list 适用场景与选型建议

jast99/sorted-linked-list 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jast99/sorted-linked-list 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jast99/sorted-linked-list 我们能提供哪些服务?
定制开发 / 二次开发

基于 jast99/sorted-linked-list 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 31
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-20