dev-master
9999999-devCached priority queue for Laravel Framework
MIT
The Requires
by David Cheung
Cached priority queue for Laravel Framework
A Priority Queue for the Laravel Framework. Easy to install, use, and store. A nice wrapper for PHP's SplPriorityQueue class., (*1)
composer require cheungd/laravel-cached-priority-queue
Find the aliases
array in config/app.php
and add the following:, (*2)
'aliases' => [ ... 'CachedPriorityQueue' => DavidCheung\LaravelCachedPriorityQueue\CachedPriorityQueue::class, ],
Initializing and interacting with the queue:, (*3)
use CachedPriorityQueue; //load the priority queue from cache if key exists $queue = new CachedPriorityQueue('my_key'); //creates queue: [John, David, Mike, Will] $queue->insert('Mike', 5); $queue->insert('Will', 5); $queue->insert('John', 1); $queue->insert('David', 1); //Will retrieve the first item 'John', but remains in queue //resulting queue: [John, David, Mike, Will] $item = $queue->peek(); //Will retrieve the first item 'John', and removes from queue //result queue: [David, Mike, Will] $item = $queue->remove(); //save in cache with key 'my_key' $queue->save();
Iterator:, (*4)
$queue = new CachedPriorityQueue('my_key'); //[John, David, Mike, Will] $queue->insert('Mike', 5); $queue->insert('Will', 5); $queue->insert('John', 1); $queue->insert('David', 1) $object = $queue->toArray(); /** array:4 [ 0 => { "data": "John" "priority": 1 } 1 => { "data": "David" "priority": 1 } 2 => { "data": "Mike" "priority": 5 } 3 => { "data": "Will" "priority": 5 } ] **/
This software is licensed under the MIT license, (*5)
Cached priority queue for Laravel Framework
MIT