vpinti/sorted-linked-list

A blazing fast, type-safe sorted linked list library for PHP. Supports automatic sorting, integer and string values, and modern PHP features.

Maintainers

Package info

github.com/vpinti/sortedLinkedList

pkg:composer/vpinti/sorted-linked-list

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2025-08-21 05:48 UTC

This package is auto-updated.

Last update: 2026-03-21 07:03:07 UTC


README

A blazing fast, type-safe, and fully tested sorted linked list library for PHP. Supports both integer and string values, with automatic sorting in ascending or descending order. Designed for performance, maintainability, and extensibility.

Features

  • Automatic sorting (ascending/descending)
  • Type safety: only one type per list (int or string)
  • Fast insert, delete, contains, clear, and iteration Internal sorting logic (no external comparator needed)
  • Simple, modern API

Installation

Install via Composer:

composer require vpinti/sorted-linked-list

Usage

use Vpinti\SortedLinkedList\SortedLinkedList;
use Vpinti\SortedLinkedList\Enum\SortOrder;

$list = new SortedLinkedList(SortOrder::ASC);
$list->insert(5);
$list->insert(2);
$list->insert(8);
$list->insert(1);

// Get sorted values as array
$values = $list->toArray(); // [1, 2, 5, 8]

// Check if a value exists
$list->contains(5); // true

// Remove a value
$list->delete(2);

// Iterate
foreach ($list as $value) {
    echo $value . PHP_EOL;
}

// Clear the list
$list->clear();

// Use with strings
$stringList = new SortedLinkedList(SortOrder::DESC);
$stringList->insert('banana');
$stringList->insert('apple');
$stringList->insert('pear');
// $stringList->toArray(); // ['pear', 'banana', 'apple']

API

SortedLinkedList

  • __construct(SortOrder $order = SortOrder::ASC)
  • insert(int|string $value): void
  • delete(int|string $value): bool
  • contains(int|string $value): bool
  • clear(): void
  • toArray(): array
  • count(): int
  • __toString(): string
  • Iterator support (foreach)

Extensibility

Sorting logic is handled internally by the SortedLinkedList class. Custom comparators are not required or supported in this version.

Contributing

Pull requests and stars are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

MIT