Download the PHP package webfiori/collections without Composer
On this page you can find all versions of the php package webfiori/collections. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webfiori/collections
More information about webfiori/collections
Files in webfiori/collections
Package collections
Short Description Basic collections set used by WebFiori.
License MIT
Informations about the package collections
WebFiori Collections
Basic data structures used by WebFiori framework.
Table of Contents
- Key Features
- Supported PHP Versions
- Installation
- Quick Start
- Usage
- LinkedList
- Stack
- Queue
- Vector
- Advanced Usage
- API Reference
- Testing
- Contributing
- License
- Support
- Changelog
Key Features
- LinkedList — Doubly-linked list with O(1) add/removeLast and full iterator support
- Stack — LIFO structure with O(1) push/pop
- Queue — FIFO structure with O(1) enqueue/dequeue
- Vector — Array-backed list with O(1) index access,
ArrayAccess, andJsonSerializable - All collections implement
Countable - Optional size limits on all collections
- Sorting support via
Comparableinterface
Supported PHP Versions
| Build Status |
|---|
Installation
Quick Start
Usage
LinkedList
The LinkedList class provides a doubly-linked list implementation with full iterator support.
LinkedList with Size Limit
Stack
The Stack class implements a Last-In-First-Out (LIFO) data structure.
Stack with Size Limit
Queue
The Queue class implements a First-In-First-Out (FIFO) data structure.
Queue with Size Limit
Vector
The Vector class provides an array-backed list with O(1) index access.
Advanced Usage
Custom Object Sorting
To sort custom objects in a LinkedList, implement the Comparable interface:
Working with References
All collections work with references, allowing you to modify objects after adding them:
API Reference
Common Methods (All Collections)
add(&$element): bool- Add an element to the collectionsize(): int- Get the number of elementstoArray(): array- Convert collection to arraycount(): int- Get element count (implements Countable)
LinkedList Specific Methods
get($index): mixed- Get element at indexgetFirst(): mixed- Get first elementgetLast(): mixed- Get last elementremove($index): mixed- Remove element at indexremoveFirst(): mixed- Remove first elementremoveLast(): mixed- Remove last element (O(1))removeElement(&$element): mixed- Remove specific elementinsert(&$element, $position): bool- Insert at positionindexOf($element): int- Find element indexcontains(&$element): bool- Check if element existscountElement(&$element): int- Count occurrencesreplace(&$old, &$new): bool- Replace elementinsertionSort($ascending = true): bool- Sort elementsclear(): void- Remove all elementsmax(): int- Get maximum capacity (-1 for unlimited)
Stack Specific Methods
push($element): bool- Add element to toppop(): mixed- Remove and return top element (O(1))peek(): mixed- View top element without removingmax(): int- Get maximum capacity (-1 for unlimited)
Queue Specific Methods
enqueue($element): bool- Add element to reardequeue(): mixed- Remove and return front elementpeek(): mixed- View front element without removingmax(): int- Get maximum capacity (-1 for unlimited)
Vector Specific Methods
get(int $index): mixed- Get element at index (O(1))set(int $index, mixed $element): void- Set element at indexinsert(mixed $element, int $index): void- Insert at positionremoveAt(int $index): mixed- Remove element at indexremove(mixed $element): mixed- Remove first occurrenceindexOf(mixed $element): int- Find element index (-1 if not found)replace(mixed $old, mixed $new): bool- Replace first occurrenceclear(): void- Remove all elementsjsonSerialize(): array- JSON serialization support- Implements
ArrayAccess:$vector[0],$vector[] = x,isset($vector[0]),unset($vector[0])
Node Methods
The Node class supports both singly and doubly linked usage:
data(): mixed- Get the stored datanext(): ?Node- Get the next nodeprev(): ?Node- Get the previous nodesetData(mixed &$data): void- Set the stored datasetNext(?Node &$next): void- Set the next nodesetPrev(?Node &$prev): void- Set the previous node
All collections use doubly-linked nodes internally, enabling O(1) removeLast() on LinkedList and O(1) pop() on Stack.
Testing
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This library is licensed under the MIT License. See the LICENSE file for more details.
Support
If you encounter any issues, please open an issue on GitHub.
Changelog
See CHANGELOG.md for a list of changes.