PHPackages                             bylec/sortedlinkedlist - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bylec/sortedlinkedlist

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bylec/sortedlinkedlist
======================

A type-safe sorted linked list for int or string values.

1.0.0(3mo ago)01↓83.3%MITPHPPHP &gt;=8.3

Since Mar 21Pushed 3mo agoCompare

[ Source](https://github.com/Bylec/sorted-linked-list)[ Packagist](https://packagist.org/packages/bylec/sortedlinkedlist)[ RSS](/packages/bylec-sortedlinkedlist/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

SortedLinkedList
================

[](#sortedlinkedlist)

A type-safe sorted linked list for PHP 8.3+.
Holds `int` or `string` values — but not both at the same time — and keeps them sorted on every insert.

Installation
------------

[](#installation)

```
composer require bylec/sortedlinkedlist
```

Quick start
-----------

[](#quick-start)

```
use SortedLinkedList\Enum\SortOrder;
use SortedLinkedList\SortedLinkedList;

$list = new SortedLinkedList();
$list->insert(5);
$list->insert(2);
$list->insert(8);
$list->insert(1);
print_r($list->toArray()); // [1, 2, 5, 8]

$desc = new SortedLinkedList(SortOrder::DESCENDING);
$desc->insert(5);
$desc->insert(2);
$desc->insert(8);
$desc->insert(1);
print_r($desc->toArray()); // [8, 5, 2, 1]

$list = SortedLinkedList::fromArray([3, 1, 4, 1, 5], SortOrder::ASCENDING);
print_r($list->toArray()); // [1, 1, 3, 4, 5]
```

### Constructor

[](#constructor)

```
new SortedLinkedList(SortOrder $order = SortOrder::ASCENDING)
```

### Mutation

[](#mutation)

MethodDescription`insert(int|string $value): void`Insert a value in sorted order`remove(int|string $value): void`Remove first occurrence; throws `ValueNotFoundException` if missing`clear(): void`Remove all values and reset the type lock### Query

[](#query)

MethodDescription`contains(int|string $value): bool`Check whether a value exists`first(): int|string`First value in list order; throws `EmptyListException``last(): int|string`Last value in list order; throws `EmptyListException``toArray(): array`All values as a plain PHP array`count(): int`Number of elements — also works with `count($list)``isEmpty(): bool`True when the list has no elements### Static factory

[](#static-factory)

```
SortedLinkedList::fromArray(array $values, SortOrder $order = SortOrder::ASCENDING): self
```

### Interfaces implemented

[](#interfaces-implemented)

- `Countable` — use `count($list)`
- `IteratorAggregate` — use `foreach ($list as $value)`

Exceptions
----------

[](#exceptions)

All exceptions extend `SortedLinkedListException extends \RuntimeException`.

ExceptionThrown when`TypeMismatchException`A value of the wrong type is inserted or queried`ValueNotFoundException``remove()` is called with a value not in the list`EmptyListException``first()` or `last()` is called on an empty list```
use SortedLinkedList\Exception\TypeMismatchException;

try {
    $list->insert('oops'); // list holds ints
} catch (TypeMismatchException $e) {
    echo $e->getMessage();
    // Type mismatch: list holds 'int' values, but 'string' was given.
}
```

Development
-----------

[](#development)

```
composer install

composer test     # run PHPUnit
composer stan     # run PHPStan (level max)
composer cs       # run PHP_CodeSniffer (PSR-12)
composer cs-fix   # auto-fix code style
composer check    # run all three
```

Project structure
-----------------

[](#project-structure)

```
src/
├── Enum/
│   └── SortOrder.php
├── Exception/
│   ├── SortedLinkedListException.php
│   ├── TypeMismatchException.php
│   ├── EmptyListException.php
│   └── ValueNotFoundException.php
├── Node.php
└── SortedLinkedList.php
tests/
└── SortedLinkedListTest.php

```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance82

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

94d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30a14657db335736579286b4d0a5c523da315e64cb5c7ce20808750e41d91d65?d=identicon)[Bylec](/maintainers/Bylec)

---

Tags

linked listsorteddata structure

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bylec-sortedlinkedlist/health.svg)

```
[![Health](https://phpackages.com/badges/bylec-sortedlinkedlist/health.svg)](https://phpackages.com/packages/bylec-sortedlinkedlist)
```

###  Alternatives

[loophp/phptree

An implementation of tree data structure

981.8M2](/packages/loophp-phptree)[chdemko/sorted-collections

Sorted Collections for PHP &gt;= 8.4

222.6M3](/packages/chdemko-sorted-collections)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
