cancio-labs/php-queue
最新稳定版本:v1.1.0
Composer 安装命令:
composer require cancio-labs/php-queue
包简介
Interface and an array-based implementation of the FIFO Queue data structure.
关键字:
README 文档
README
This tiny package contains an interface and an array-based implementation of the FIFO Queue data structure.
Interface
The Queue interface extends both Countable and IteratorAggragate interfaces, so it's possible to use a queue object inside the count function and foreach loop.
Methods
| Method | Description |
|---|---|
| enqueue | Adds a new element to the back of the queue. |
| dequeue | Removes and return the front element from the queue. |
| back | Returns the back element of the queue. |
| front | Returns the front element of the queue. |
| isEmpty | Tests whether the queue is empty. |
| clear | Removes all elements from the queue. |
| count | Returns the number of elements of the queue. |
| getIterator | Returns a QueueIterator. |
| toArray | Transforms the queue into an array. |
How to use it
use CancioLabs\Ds\Queue\Queue;
$queue = new Queue(['A', 'B']);
$queue->enqueue('C');
$queue->enqueue('D');
$queue->isEmpty(); // returns false
$queue->count(); // returns 4
count($queue) // returns 4
$queue->front(); // output 'A'
$queue->back(); // output 'D'
$queue->dequeue(); // output 'A'
$array = $queue->toArray(); // returns ['B', 'C', 'D']
foreach ($queue as $element) {
// i=0: $element = 'B'
// i=1: $element = 'C'
// i=2: $element = 'D'
}
$queue->isEmpty(); // returns true
Tests and Coverage
All tests are passing with no warnings and code coverage is 100%.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-03-04