Download the PHP package d-skora/simple-sorted-linked-list without Composer
On this page you can find all versions of the php package d-skora/simple-sorted-linked-list. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download d-skora/simple-sorted-linked-list
More information about d-skora/simple-sorted-linked-list
Files in d-skora/simple-sorted-linked-list
Download d-skora/simple-sorted-linked-list
More information about d-skora/simple-sorted-linked-list
Files in d-skora/simple-sorted-linked-list
Vendor d-skora
Package simple-sorted-linked-list
Short Description A type-safe sorted linked list for PHP 8.2+, with stable scalar typing, custom sort order, and mutation-safe iteration.
License MIT
Package simple-sorted-linked-list
Short Description A type-safe sorted linked list for PHP 8.2+, with stable scalar typing, custom sort order, and mutation-safe iteration.
License MIT
Please rate this library. Is it a good library?
Informations about the package simple-sorted-linked-list
Simple Sorted Linked List
A type-safe sorted singly linked list for PHP 8.2+. Items are kept in sorted order at all times, with stable scalar typing while non-empty, a pluggable sort order, and an iterator that remains safe even when the list is mutated during foreach.
Features
- Always sorted — items are inserted in the correct position, not sorted on read
- Stable scalar typing — while non-empty, the list accepts only one scalar
type (
intorstring); after becoming empty, it can accept either type again - Ascending, descending, or custom order — pass any comparator callable
- Mutation-safe iteration — you can
remove(),removeAll(), orclear()inside aforeachwithout corrupting the iterator - Rich query API —
first(),last(),at(int $index),contains(),countOccurrences(),toArray() - Functional helpers —
copy(),filter(),merge() - Zero runtime dependencies — only
php: ^8.2
Installation
Quick start
Ascending list of integers
Descending list of strings
Custom comparator
Inserting and removing
Filter and merge
Safe mutation during foreach
API reference
| Method | Description |
|---|---|
SortedLinkedList::create(iterable, SortOrder) |
Static factory |
insert(int\|string) |
Insert preserving order |
remove(int\|string): bool |
Remove first occurrence |
removeAll(int\|string): bool |
Remove all occurrences |
first(): int\|string |
Head value (throws on empty) |
last(): int\|string |
Tail value (throws on empty) |
at(int): int\|string |
Value at zero-based index |
contains(int\|string): bool |
Membership check |
countOccurrences(int\|string): int |
Count of a specific value |
count(): int |
Total item count (Countable) |
toArray(): list<int\|string> |
Snapshot as array |
clear() |
Empty the list |
copy() |
Independent copy |
filter(callable): self |
New filtered list |
merge(SortedLinkedListInterface): SortedLinkedListInterface |
New merged list |
getIterator() |
foreach-compatible iterator |
Sort orders
| Factory | Behaviour |
|---|---|
SortOrder::ascending() |
Natural ascending (integers by value, strings alphabetically) |
SortOrder::descending() |
Natural descending |
SortOrder::custom(callable) |
Comparator fn(a, b): int — same contract as usort |
Exceptions
| Exception | Thrown when |
|---|---|
InvalidArgumentException |
Wrong scalar type inserted, incompatible scalar comparisons, or scalar-type mismatch while merging |
UnderflowException |
first() / last() on empty list, or current() on exhausted iterator |
OutOfBoundsException |
at() with out-of-range index |
RuntimeException |
Custom comparator returns a non-int, or comparator is not set |
Development
License
MIT © Daniel Skora
All versions of simple-sorted-linked-list with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.2
The package d-skora/simple-sorted-linked-list contains the following files
Loading the files please wait ...