PHPackages                             hoa/heap - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hoa/heap

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

hoa/heap
========

The Hoa\\Heap library.

5102[1 PRs](https://github.com/hoaproject/Heap/pulls)PHP

Since Nov 6Pushed 8y ago6 watchersCompare

[ Source](https://github.com/hoaproject/Heap)[ Packagist](https://packagist.org/packages/hoa/heap)[ RSS](/packages/hoa-heap/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

[![Build status](https://camo.githubusercontent.com/af5b5e37b7a63b8468ae0c3234c94004abe82cb2a68e5d3043272b249bc7e182/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f686561702f6d61737465722e737667)](https://travis-ci.org/hoaproject/heap)[![Coverage](https://camo.githubusercontent.com/8209483c13fb92bf64e2e3cf94f2cd0a93fab03ffec658a738dc305b49cc8c42/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f686561702f6d61737465722e737667)](https://coveralls.io/github/hoaproject/heap?branch=master)[![Packagist](https://camo.githubusercontent.com/bf10c99ea562d29015552a89ed152f508c75c91407bb2b69553e57d8d4b52ce4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f686561702e737667)](https://packagist.org/packages/hoa/heap)[![License](https://camo.githubusercontent.com/1d72564fec7c81f3096c08eff258aeddf503e0dbeacfda4ae41faef62353641c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f686561702e737667)](https://hoa-project.net/LICENSE)

Hoa is a **modular**, **extensible** and **structured** set of PHP libraries. Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Heap
=========

[](#hoaheap)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://hoa-project.net/Literature/Hack/heap.html)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/heap)

This library provides a set of advanced Heap can support *Scalar*, *Array*, *Object* or *Closure*as item and not only Integer, as ordinal does. The order of heap depends of priority parameter.

`Hoa\Heap\Min` and `Hoa\Heap\Max` class interpret priority by comparing items numerically. But you are free to implement your own class if you want a different sort algorithm.

⚠️ Warning
----------

[](#warning-warning)

The default iteration process do not dequeue the Heap as common usage. You must use Generator methods `top` or `pop` for iterate on with remove item from heap.

Installation
------------

[](#installation)

With [Composer](http://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/heap`](https://packagist.org/packages/hoa/heap):

```
$ composer require hoa/heap '~0.0'
```

For more installation procedures, please read [the Source page](http://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Considering the library has been installed with Composer, the following commands will run the test suites:

```
$ composer install
$ vendor/bin/hoa test:run
```

For more information, please consult the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

As a quick overview, we propose to see a simple use case with a `Phone number`, This phone number must be sent to three methods in a strict order, `Check`, `Transform`, `Format`.

Let's assume we don't have access to iteration process. But we can sort in which orders our methods must be called for respect our process.

### Register Callback

[](#register-callback)

In first, we will create our callbacks process.

```
require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';

// First method used to check if phone number is correct.
$check = function($phone) {
    if (1 !== preg_match('/^\+?[0-9]+$/', $phone)) {
        throw new \Exception('Phone number not conform.');
    }

    return $phone;
};

// Second method used to convert number into object.
$transform = function($phone) {
    return (object)[
        'prefix'  => '+33',
        'country' => 'France',
        'number'  => $phone,
    ];
};

// Third method used to display formatted number.
$format = function(\StdClass $phone) {
    return $phone->prefix
        . ' '
        . wordwrap($phone->number, 3, ' ', true)
    ;
};
```

### Create and fill Heap

[](#create-and-fill-heap)

Creation of our Heap with minimum priority Ascending ( lower called first ).

```
$heap = new \Hoa\Heap\Min();

// Insert the callback method with the priority argument used for order Heap.
$heap->insert($transform, 20);
$heap->insert($check, 10);
$heap->insert($format, 30);

// Show the number of item in Heap.
var_dump(
    $heap->count()
);

/**
 * Will output:
 *     int(3)
 */
```

### Iteration Heap

[](#iteration-heap)

Then we can iterate on our `Heap` with assurance of correct call order. Spread your number into closure and have process mutation expected.

```
// Phone number as expected by first callback.
$number = '123001234';

foreach ($heap as $closure) {
    try {
        // Mutation of number by closure, execute in the priority order expected.
        $number = $closure($number);
    } catch (\Exception $e) {
        break;
    }
}

// Finally, we can display our formatted number.
var_dump($number);

/**
 * Will output:
 *     string(15) "+33 123 001 234"
 */
```

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\heap`](https://hoa-project.net/Literature/Hack/heap.html) contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

Related projects
----------------

[](#related-projects)

There are no related project registered, Let us know by opening issue if you use it and want be listed!

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.4% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a410060743cec0e0d8654661b726a7a25f5888f18059d4c942a8fd9a8128f0da?d=identicon)[Hoa](/maintainers/Hoa)

---

Top Contributors

[![Pierozi](https://avatars.githubusercontent.com/u/5133487?v=4)](https://github.com/Pierozi "Pierozi (17 commits)")[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (1 commits)")

---

Tags

heaphoalibraryphp

### Embed Badge

![Health badge](/badges/hoa-heap/health.svg)

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

###  Alternatives

[clausnz/php-helpers

A Collection of useful php helper functions.

388.7k](/packages/clausnz-php-helpers)

PHPackages © 2026

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