PHPackages                             rulinski/sorted-linked-list - 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. rulinski/sorted-linked-list

ActiveLibrary

rulinski/sorted-linked-list
===========================

A type-safe sorted linked list supporting int or string values (not both).

v1.0.0(1mo ago)03MITPHPPHP ^8.4

Since Jul 15Pushed 1mo agoCompare

[ Source](https://github.com/Rulinski/sorted-linked-list)[ Packagist](https://packagist.org/packages/rulinski/sorted-linked-list)[ RSS](/packages/rulinski-sorted-linked-list/feed)WikiDiscussions main Synced 1w ago

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

Sorted Linked List
==================

[](#sorted-linked-list)

A small, type-safe PHP library implementing a linked list that keeps its elements sorted at all times. A single list instance holds either `int` or `string` values — never both — with the type declared explicitly when the list is created.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.4

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

[](#installation)

```
composer require rulinski/sorted-linked-list
```

Usage
-----

[](#usage)

```
use Rulinski\SortedLinkedList\SortedLinkedList;

$list = new SortedLinkedList(SortedLinkedList::TYPE_INT);

$list->add(5);
$list->add(1);
$list->add(3);

$list->toArray();     // [1, 3, 5]
(string) $list;        // "[1, 3, 5]"
$list->contains(3);    // true
$list->first();        // 1
$list->last();         // 5
count($list);          // 3

foreach ($list as $value) {
    // 1, 3, 5
}

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

```
$strings = new SortedLinkedList(SortedLinkedList::TYPE_STRING);
$strings->add('banana');
$strings->add('apple');

$strings->toArray();   // ['apple', 'banana']

$strings->add(42);     // throws InvalidValueTypeException
```

Design notes
------------

[](#design-notes)

- **Type is fixed at construction**, not inferred from the first inserted value. This makes the contract explicit at the call site and fails fast on misuse, rather than silently locking in a type based on insertion order.
- **Duplicates are allowed.** This is a sorted list, not a sorted set. `remove()` removes only the first matching occurrence and returns whether anything was removed; call it repeatedly (or in a loop) to remove all matches.
- **`first()`/`last()` throw `EmptyListException`** on an empty list rather than returning `null`, so callers can't silently mistake "empty" for a valid `0`/`''` value.
- **Ordering** is ascending: numeric comparison for `int`, `strcmp` for `string`. Custom comparators are intentionally out of scope.
- **Complexity:** `add()`, `remove()`, `contains()` are O(n) (list traversal to find the sorted position / matching node). `first()` / `isEmpty()` / `count()` are O(1). `last()` is O(n) (singly linked, no tail pointer).
- Implements `Countable`, `IteratorAggregate`, and `Stringable` so it behaves like a native PHP collection (`count()`, `foreach`, string casting all work as expected).

Testing
-------

[](#testing)

```
composer test    # PHPUnit
composer stan    # PHPStan (max level)
```

### Author

[](#author)

[Vitali Rulinski](mailto:vital.rulinski@gmail.com)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7301b44e4a2646f7f5da21e4ca1a7a445c52b7091ae3b131ad24018497324f4d?d=identicon)[Vital Rulinski](/maintainers/Vital%20Rulinski)

---

Top Contributors

[![Rulinski](https://avatars.githubusercontent.com/u/5849108?v=4)](https://github.com/Rulinski "Rulinski (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rulinski-sorted-linked-list/health.svg)

```
[![Health](https://phpackages.com/badges/rulinski-sorted-linked-list/health.svg)](https://phpackages.com/packages/rulinski-sorted-linked-list)
```

PHPackages © 2026

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