A collection of reusable and efficient data structures for various use cases.
Data Structure | Status |
---|---|
Sorted Linked List | β Implemented |
Other structures (coming soon) | β³ Planned |
A linked list that automatically keeps your values sorted. Supports integers or strings.
- 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.
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]
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]
Easily remove any value from the list.
$list->remove(2); // [3, 1]
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
}
Add the dependency to your project:
composer require slimapi/data-structure
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
This project is licensed under the terms specified in the LICENSE file.
We welcome contributions and suggestions! Please report any issues in the issue tracker.