PHPackages                             jihel/library-rbtree - 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. jihel/library-rbtree

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

jihel/library-rbtree
====================

A library to implement Red Black Tree

89.1k↓50%3[1 issues](https://github.com/Jihell/LibraryRBTree/issues)PHP

Since Feb 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Jihell/LibraryRBTree)[ Packagist](https://packagist.org/packages/jihel/library-rbtree)[ RSS](/packages/jihel-library-rbtree/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Jihel's RB Tree PHP implementation
==================================

[](#jihels-rb-tree-php-implementation)

PHP OOP implementation of Red Black Tree. You can found information about this kind of binary search tree on [wikipedia](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree).

1- Install
----------

[](#1--install)

Add library to your composer.json require:

```
{
    "require": {
        "jihel/library-rbtree": "dev-master",
    }
}

```

or

```
php composer.phar require jihel/library-rbtree

```

2- Usage
--------

[](#2--usage)

### a) Create a tree:

[](#a-create-a-tree)

```
use Jihel\Library\RBTree\Tree as Tree;
$tree = new Tree();

```

### b) Create a node:

[](#b-create-a-node)

```
$node = new Jihel\Library\RBTree\Node(1, 'My value');
$tree->insert($node);

```

### c) Delete a node:

[](#c-delete-a-node)

```
$tree->remove($node);

```

Please note that the var $node is not deleted, the object still exist but is detached from the tree.

### d) Find a node:

[](#d-find-a-node)

```
$node = $tree->find(1);

```

### e) Find a node relative to another:

[](#e-find-a-node-relative-to-another)

```
$next = $tree->findRelative($node, Jihel\Library\RBTree\Model\NodeInterface::POSITION_RIGHT);
// or
$next = $tree->findSuccessor($node);

```

### f) Enumerate nodes between a min and max

[](#f-enumerate-nodes-between-a-min-and-max)

```
$list = $tree->enumerate(1, 12);

```

You can look at exemples for a simple implementation with integer nodes :

- [cli.php](exemple/cli.php)
- [html.php](exemple/index.php)

4- Thanks
---------

[](#4--thanks)

I inspired from the work of Gokce Toykuyu from the MIT. See his [implementation](http://web.mit.edu/~emin/Desktop/ref_to_emin/www.old/source_code/red_black_tree/index.html)

There is also some youtube video of a RB Tree at work who might interest you :

-
-

Thanks to me for giving my free time doing class for lazy developers.

You can access read CV [here](http://www.joseph-lemoine.fr)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 60% 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/19ed41f54971ca2c9a6d2cd25178b46b7d38164bc8a16b046dc0556c5871d991?d=identicon)[Jihel](/maintainers/Jihel)

---

Top Contributors

[![jcluox](https://avatars.githubusercontent.com/u/25052120?v=4)](https://github.com/jcluox "jcluox (3 commits)")[![Jihell](https://avatars.githubusercontent.com/u/3269035?v=4)](https://github.com/Jihell "Jihell (2 commits)")

### Embed Badge

![Health badge](/badges/jihel-library-rbtree/health.svg)

```
[![Health](https://phpackages.com/badges/jihel-library-rbtree/health.svg)](https://phpackages.com/packages/jihel-library-rbtree)
```

###  Alternatives

[keiko/uuid-shortener

A simple shortener library for RFC 4122 compatible UUIDs. Change your 36 chars long UUID into it's shorter equivalent.

150215.4k2](/packages/keiko-uuid-shortener)[visualappeal/php-auto-update

Autoupdater for PHP

24136.3k](/packages/visualappeal-php-auto-update)[magefan/module-conflict-detector

Detect extension conflicts

4872.6k2](/packages/magefan-module-conflict-detector)

PHPackages © 2026

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