Skip to content

Files

Latest commit

 

History

History
106 lines (80 loc) · 3.54 KB

README.md

File metadata and controls

106 lines (80 loc) · 3.54 KB

📚 SlimAPI - Data Structures

PHP Version Release License Build Code Coverage PHPStan

A collection of reusable and efficient data structures for various use cases.

Data Structure Status
Sorted Linked List ✅ Implemented
Other structures (coming soon) ⏳ Planned

🔗 SlimAPI\DataStructure\SortedLinkedList

A linked list that automatically keeps your values sorted. Supports integers or strings.

✨ Features

  • Automatic Sorting: Always keeps elements sorted.
  • Customizable Direction: Sort in ascending (default) or descending order.
  • Duplicate Prevention: Automatically ensures only unique elements are stored in the list.
  • Operations: Insert O(n), remove O(n), count O(1), and iterate O(n) with ease.

📚 Usage Examples

✅ Adding Items to the List

Values are inserted while maintaining the sort order.

$list = new SortedLinkedList();
$list->insert(3); // [3]
$list->insert(1); // [1, 3]
$list->insert(2); // [1, 2, 3]

🔄 Changing Sort Direction

You can control the sorting order by specifying Direction::ASC (default) or Direction::DESC.

$list = new SortedLinkedList(Direction::DESC);
$list->insert(3); // [3]
$list->insert(1); // [3, 1]
$list->insert(2); // [3, 2, 1]

❌ Removing Items

Easily remove any value from the list.

$list->remove(2); // [3, 1]

🔢 Counting and Iterating

The list is both countable and iterable, perfect for large datasets.

echo $list->count(); // 2

foreach ($list->toGenerator() as $item) {
    echo $item; // Outputs 3, then 1
}

📦 Installation

Add the dependency to your project:

composer require slimapi/data-structure

🛠️ Local Development & Testing

Clone the repo, then use the power of make to simplify your workflow:

make help  # See all available commands
make run   # Start the app container
make test  # Run tests and code checkers

📜 License

This project is licensed under the terms specified in the LICENSE file.

🌟 Get Involved

We welcome contributions and suggestions! Please report any issues in the issue tracker.