PHPackages                             thomaslarsson/priorityqueue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. thomaslarsson/priorityqueue

ActiveLibrary

thomaslarsson/priorityqueue
===========================

Ascending/descending PriorityQueues. Order maintained for nodes with equal priority on dequeue

v1.0.0(12y ago)0425MITPHPPHP &gt;=5.3.0

Since Oct 2Pushed 12y ago1 watchersCompare

[ Source](https://github.com/thomaslarsson/PriorityQueue)[ Packagist](https://packagist.org/packages/thomaslarsson/priorityqueue)[ Docs](http://github.com/ThomasLarsson/PriorityQueue)[ RSS](/packages/thomaslarsson-priorityqueue/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (2)Used By (0)

PriorityQueue [![Build Status](https://camo.githubusercontent.com/a61701aee0e584633d7d1d93dc99294b145e93386abbb8039000c0d646c45faf/68747470733a2f2f6170692e7472617669732d63692e6f72672f74686f6d61736c617273736f6e2f5072696f7269747951756575652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/thomaslarsson/PriorityQueue)
======================================================================================================================================================================================================================================================================================================================================

[](#priorityqueue-)

Ascending/descending PriorityQueues. Order maintained for nodes with equal priority on dequeue.

#### Install

[](#install)

You can install the package using Composer.

1. Install composer.
2. Add the following dependency to a composer.json and:

```
{
    "require": {
        "thomaslarsson/priorityqueue": "1.0.*"
    }
}

```

The package is now installed in your vendor directory.

#### Usage

[](#usage)

```
// Require composer's autoload
require 'vendor/autoload.php';

// Optional: Alias/import the package's namespace
use ThomasLarsson\PriorityQueue\MinPriorityQueue as MinPriorityQueue,
    ThomasLarsson\PriorityQueue\MaxPriorityQueue as MaxPriorityQueue;

// Create a ascending queue (Use the package's namespace unless you aliased it)
$ascendingQueue = new MinPriorityQueue();

// ... OR a descending queue.
$descendingQueue = new MaxPriorityQueue(); // A decending queue

// Create some data sorted descending (Just to illustrate that it's working)
$ascendingQueue->insert(4, 0);
$ascendingQueue->insert(3, 0);
$ascendingQueue->insert(2, 0);
$ascendingQueue->insert(1, 0);
$ascendingQueue->insert(0, 0);

// Display the sorted result
foreach ( $ascendingQueue as $value )
{
    echo $value . "\n";
}

```

### Fixes equal priority sorting bug

[](#fixes-equal-priority-sorting-bug)

ThomasLarsson/PriorityQueue is built on top of [SplPriorityQueue](http://www.php.net/manual/en/class.splpriorityqueue.php). This implementation fixes problems when two or more nodes share a similar priority. The standard SPL-implementation will dequeue equal priority nodes in no particular (random) order, as noted in the manual.

> ##### SPLPriorityQueue::compare()
>
> [](#splpriorityqueuecompare)
>
> **Note:**Multiple elements with the same priority will get dequeued in no particular order.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4608d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2387501202ea3d3b2b8e90765f330e3f725d7352a67799d2b73c2189ad40dbba?d=identicon)[ThomasLarsson](/maintainers/ThomasLarsson)

---

Top Contributors

[![Juvenorge](https://avatars.githubusercontent.com/u/5555170?v=4)](https://github.com/Juvenorge "Juvenorge (9 commits)")[![thomaslarsson](https://avatars.githubusercontent.com/u/1395646?v=4)](https://github.com/thomaslarsson "thomaslarsson (9 commits)")

---

Tags

PriorityQueueAscending PriorityQueueDescending PriorityQueueOrder maintained for nodes with equal priority on dequeue

### Embed Badge

![Health badge](/badges/thomaslarsson-priorityqueue/health.svg)

```
[![Health](https://phpackages.com/badges/thomaslarsson-priorityqueue/health.svg)](https://phpackages.com/packages/thomaslarsson-priorityqueue)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
