justblackbird/stable-priority-queue
Composer 安装命令:
composer require justblackbird/stable-priority-queue
包简介
Stable implementation of priority queue
README 文档
README
Stable implementation of priority queue data structure in PHP.
Why
There is an implementation of priority queue in SPL: SplPriorityQueue. The problem is it is unstable. Take a look at the example below:
$q = new \SplPriorityQueue(); $q->insert(1, 0); $q->insert(2, 0); $q->insert(3, 0); $q->insert(4, 0); while (!$q->isEmpty()) { echo $q->extract() . " "; }
This example retrieves a string "1 4 3 2" and not "1 2 3 4". This library provides an implementation that extracts values of the same priorites in the order they came in. The example above will return "1 2 3 4"!
Installation
composer require justblackbird/stable-priority-queue
Usage
use JustBlackBird\StablePriorityQueue\Queue; $q = new Queue(); $q->insert(1, 0); $q->insert(2, 0); $q->insert(3, 0); $q->insert(4, 0); while (!$q->isEmpty()) { echo $q->extract() . " "; } // "1 2 3 4" will be outputted.
License
MIT (c) Dmitry Simushev
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-08-22