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

ActiveLibrary

martingold/linked-list
======================

Library providing sorted linked list

0.1.0(2y ago)03MITPHPPHP &gt;=8.2

Since Nov 3Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

linked-list
===========

[](#linked-list)

Library providing a standard sorted linked list implementation. The strict variant is offered for ensuring types in the list, making it suitable for non-typechecked codebases.

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

[](#installation)

You can install this library using [Composer](https://getcomposer.org/):

```
composer require martingold/linked-list
```

Usage
-----

[](#usage)

```
require 'vendor/autoload.php';

use MartinGold\LinkedList\SortedLinkedList;

$list = new SortedLinkedList();

$list->insert(1);
$list->insert(3);
$list->insert(7);

var_dump($list->pop());
```

Following list operations are supported: `insert`, `get`, `contains`, `shift`, `pop`

In case runtime checking is required in a non-typesafe codebase, consider using the StrictSortedLinkedList implementation, which performs type checking at runtime.

### Implementing custom sorting

[](#implementing-custom-sorting)

The default implementation of sorting is done using spaceship operator. You may use your own implementation of `Comparator` in case you need to sort values depending on your needs.

```
use MartinGold\LinkedList\Comparator\Comparator;
use MartinGold\LinkedList\SortedLinkedList;

class Product
{
    public function __construct(
        public readonly float $quantity,
    ){
        //
    }
}

/**
 * @implements Comparator
 */
class ProductComparator implements Comparator
{
    /**
     * Returns 1 when $a value is greater than $b.
     * Returns 0 when $a value is same as $b value.
     * Returns -1 when $a value is lesser than $b.
     */
    public function compare(Product $a, Product $b): int
    {
        return $a->quantity  $b->quantity;
    }
}

$productList = new SortedLinkedList(new ProductComparator());
$productList->insert(new Product(20));
$productList->insert(new Product(31));
$productList->insert(new Product(12));

foreach ($productList as $product) {
    echo $product->quantity;
}

// 12
// 20
// 31
```

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

[](#requirements)

```
php >= 8.2

```

No other dependency required.

Contributing
------------

[](#contributing)

Modify the library as needed and then run

```
composer qa
```

Please ensure that this script passes successfully before submitting a pull request. The script performs checks for adherence to coding standards and performs static analysis checks.

If you encounter code-style errors, you can automatically fix them by running:

```
composer csf
```

License
-------

[](#license)

This library is open-source and available under the MIT License.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

927d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/03a0120fc880b0d44d457896546142bd1212d15e92d9e67d9d0272e5cf272705?d=identicon)[martingold](/maintainers/martingold)

---

Top Contributors

[![martingold](https://avatars.githubusercontent.com/u/15158789?v=4)](https://github.com/martingold "martingold (13 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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