PHPackages                             sergiobelya/data-structures - 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. sergiobelya/data-structures

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

sergiobelya/data-structures
===========================

PHP library for data structures like Sorted Linked List

1.0.0(5mo ago)01MITPHPPHP ^8.3

Since Jan 7Pushed 5mo agoCompare

[ Source](https://github.com/sergiobelya/php-data-structures)[ Packagist](https://packagist.org/packages/sergiobelya/data-structures)[ RSS](/packages/sergiobelya-data-structures/feed)WikiDiscussions main Synced today

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

sergiobelya/data-structures
===========================

[](#sergiobelyadata-structures)

PHP library for data structures like Sorted Linked List

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

[](#installation)

```
composer require sergiobelya/data-structures
```

Sorted Linked List
------------------

[](#sorted-linked-list)

The data structure that consists of elements, each containing a link to the next element, and all elements are always kept sorted. One instance of SortedLinkedList contains `int` or `string` values but not both.

### Available actions

[](#available-actions)

- add
- delete
- shift
- pop
- isValueExists
- count
- reverse
- toArray
- iterate

### Usages

[](#usages)

Notice: each `$value` used for one instance of `SortedLinkedList` should be `int` or `string` but not both, otherwise `\InvalidArgumentException` will be thrown.

#### Add

[](#add)

```
use Sergiobelya\DataStructures\SortedLinkedList;

// 1 example
$list = new SortedLinkedList();
while ($value = /* some function, e.g. fetch record from DB, read row from file, pop value from array, etc. */) {
    $list->add($value);
}

// 2 example
$sortedListInt = new SortedLinkedList();
$sortedListInt->add(5);
$sortedListInt->add(15);
$sortedListInt->add(10);

// 3 example
$sortedListString = new SortedLinkedList();
$sortedListString->add('USA');
$sortedListString->add('Canada');
$sortedListString->add('Mexico');
```

#### Delete

[](#delete)

```
// Delete value from SortedLinkedList
$sortedListInt->delete(10);

// Delete value from SortedLinkedList
$sortedListString->delete('Mexico');
```

#### Shift &amp; Pop

[](#shift--pop)

```
$firstValue = $list->shift();
$lastValue = $list->pop();
```

#### Is Value Exists

[](#is-value-exists)

```
if ($list->isValueExists('USA')) {
    // do something
}
```

#### Count

[](#count)

```
$countItems = $list->count();
// or
$countItems = count($list);
```

#### Reverse

[](#reverse)

```
// 1st option - call reverse() before add()
$sortedList = new SortedLinkedList();
$sortedList->reverse();
foreach ($originalData as $value) {
    // add values in descending order
    $sortedList->add($value);
}

// 2nd option - call reverse() after add()
$sortedList = new SortedLinkedList();
foreach ($originalData as $value) {
    // add values in ascending order
    $sortedList->add($value);
}
// reverse all values in descending order
$sortedList->reverse();
```

#### To Array

[](#to-array)

```
$data = $list->toArray();
```

#### Iterations

[](#iterations)

```
foreach ($list as $value) {
    // do something
}
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance70

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

176d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6141086?v=4)[Sergei Belyakov](/maintainers/sergiobelya)[@sergiobelya](https://github.com/sergiobelya)

---

Top Contributors

[![sergiobelya](https://avatars.githubusercontent.com/u/6141086?v=4)](https://github.com/sergiobelya "sergiobelya (18 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sergiobelya-data-structures/health.svg)

```
[![Health](https://phpackages.com/badges/sergiobelya-data-structures/health.svg)](https://phpackages.com/packages/sergiobelya-data-structures)
```

PHPackages © 2026

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