PHPackages                             jakubkulhan/btree - 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. jakubkulhan/btree

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

jakubkulhan/btree
=================

Append-only B+Tree implemented purely in PHP.

8018.2k12[1 issues](https://github.com/jakubkulhan/btree/issues)[2 PRs](https://github.com/jakubkulhan/btree/pulls)PHP

Since Mar 29Pushed 8y ago8 watchersCompare

[ Source](https://github.com/jakubkulhan/btree)[ Packagist](https://packagist.org/packages/jakubkulhan/btree)[ RSS](/packages/jakubkulhan-btree/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

btree
=====

[](#btree)

Append-only B+Tree implemented purely in PHP. Intended to be an efficient key-value storage. B+Tree is a very popular in storage systems (databases) because of its fast retrieval even with millions of records.

API
---

[](#api)

Get the instance:

```
$btree = btree::open('my.tree');

```

`btree::open()` takes one argument – path to file with B+Tree. If file does not exists, it is created for you. `btree::open()` returns `FALSE` in case that anything went wrong, newly created otherwise.

Set (insert, update) a value for some key:

```
$btree->set('key', 'value');

```

`set()` returns `FALSE` on failure, `TRUE` otherwise.

Get the value:

```
$btree->get('key');

```

If key does not exist or anything goes wrong, `get()` returns `NULL`. Value under the key is returned otherwise.

Delete key:

```
$btree->set('key', NULL);

```

`NULL`s (deletes) the key. Same return values as in case of inserting/updating value.

That is all you need.

Advanced
--------

[](#advanced)

### Range searches

[](#range-searches)

```
$btree->range("startkey", "endkey");

```

And you'll get array of values whose key is greater than or equal to "startkey" and less than "endkey".

### Get all values

[](#get-all-values)

`range()` (assuming you do not have keys like "\\xff\\xff...") should do it:

```
$values = $btree->range("\x00", "\xff");

```

Or get pointers to all leaf nodes:

```
$leaves = $btree->leaves();

```

And then process nodes:

```
$values = array();
foreach ($leaves as $p) {
    list(,$leaf) = $btree->node($leaf);
    $values += $leaf;
}

```

Using `leaves()` is depracted.

### Compaction

[](#compaction)

Does your B+Tree consume a lot of space? Then compact it:

```
$btree->compact();

```

License
-------

[](#license)

The MIT license:

```
Copyright (c) 2009-2010 Jakub Kulhan

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

```

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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/336ce4f2acf4ba19e86fe9edd33831c36d48e61858878d86af2b59728bf0a1a4?d=identicon)[jakubkulhan](/maintainers/jakubkulhan)

---

Top Contributors

[![jakubkulhan](https://avatars.githubusercontent.com/u/95001?v=4)](https://github.com/jakubkulhan "jakubkulhan (15 commits)")

### Embed Badge

![Health badge](/badges/jakubkulhan-btree/health.svg)

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

###  Alternatives

[responsiv/currency-plugin

Currency plugin for October CMS

171.3k1](/packages/responsiv-currency-plugin)

PHPackages © 2026

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