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

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

assassin215k/btree
==================

Btree collection indexing

0.1.0(4y ago)08MITPHPPHP &gt;=8.1

Since Jan 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/iceorb-com-ua/btree)[ Packagist](https://packagist.org/packages/assassin215k/btree)[ Docs](https://github.com/iceorb-com-ua/btree)[ RSS](/packages/assassin215k-btree/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (5)Used By (0)

Btree
=====

[](#btree)

[![Latest Version](https://camo.githubusercontent.com/2a5c8a5f6c538d4ad0ff2c12d4b1770b6add5d2ae794a764082552b81a3c9a09/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f617373617373696e3231356b2f62747265652e737667)](https://github.com/assassin215k/btree/releases)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE.md)[![codecov](https://camo.githubusercontent.com/34430648475c9cdd5a8099d979ecaaba5ce422176c82f4de1bc3b07a461d5341/68747470733a2f2f636f6465636f762e696f2f67682f6963656f72622d636f6d2d75612f62747265652f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d574a4c50414c4f49303026)](https://codecov.io/gh/iceorb-com-ua/btree/branch/master)[![Codecov](https://camo.githubusercontent.com/6b575d4fab9e2684f4d6edae25a59f0931d00b4db0195a368cf037f669bd5802/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6963656f72622d636f6d2d75612f62747265652f6272616e63682f6465763f6c6162656c3d636f6465636f7625323064657626636f6c6f723d6c6967687467726179)](https://codecov.io/gh/iceorb-com-ua/btree/branch/dev)[![Total Downloads](https://camo.githubusercontent.com/038b69f158196a09529991f8f27c5948616a105c9b4cc597dd5675caf25e9325/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617373617373696e3231356b2f62747265652e737667)](https://packagist.org/packages/assassin215k/btree)

Provides btree-indexation for an object collection. Provide sorting, ordering and composite indexes. Writes with PSR12 support

Install
-------

[](#install)

Via Composer

```
$ composer require assassin215k/btree
```

Create collection and index
---------------------------

[](#create-collection-and-index)

Use objects with same public properties.

```
use Btree\IndexedCollection;

$collection = new IndexedCollection($data);
$collection->addIndex(['name', 'age']);
```

Can be used multiple indexes for different properties

```
$collection = new IndexedCollection(data: $data);
$collection->addIndex(['name', 'age']);
$collection->addIndex(['name']);
$collection->addIndex('age');
```

Use own Builder and/or Index, that implements BuilderInterface and/or IndexInterface

```
use Btree\Builder\BuilderInterface;
use Btree\Index\IndexInterface;

class OwnBuilder implements BuilderInterface{};
class OwnIndex implements IndexInterface{};

$collection = new IndexedCollection(options: [
'builderClass' => OwnBuilder:class
'indexClass' => OwnIndex:class
]);
```

Configure degree of default btree index, 100 by default

```
use Btree\Index\Btree\Index;

Index::$nodeSize = 10;
$collection = new IndexedCollection();
```

Use custom index class that implements IndexInterface

```
class OwnIndex implements IndexInterface {}

$collection = new IndexedCollection(data: []);
$collection->addIndex('name', new OwnIndex());
```

Drop index
----------

[](#drop-index)

```
$collection->dropIndex(['name', 'age']);
$collection->dropIndex('name');
```

Add to collection
-----------------

[](#add-to-collection)

Add items into collection after creating the one

```
$collection = new IndexedCollection();
$collection->addIndex(['name', 'age']);
$collection->add(new SomeClass('Sofia', 18));
```

Remove from collection
----------------------

[](#remove-from-collection)

Add items into collection after creating the one

```
$collection->delete(['name' => 'Sofia", 'age' => 18]);

$person = new SomeClass('Sofia', 18);
$collection = new IndexedCollection();
$collection->add($person);
..
$collection->delete($person);
```

Builder
-------

[](#builder)

Each builder use for one query

```
use Btree\Builder\Enum\EnumOperator;
use Btree\Builder\Enum\EnumSort;

$builder = $collection->createBuilder();

$builder->andWhere('name', EnumOperator::Equal, 'Lisa');

$builder->andWhere('country', EnumOperator::IsNull);

$builder->andWhere('age', EnumOperator::LessThen, 50);
$builder->andWhere('age', EnumOperator::LessThenOrEqual, 50);
$builder->andWhere('age', EnumOperator::GreaterThen, 10);
$builder->andWhere('name', EnumOperator::GreaterThenOrEqual, 'A');

$builder->andWhere('age', EnumOperator::Between, [45, 15]);
$builder->andWhere('name', EnumOperator::Between, ['A','Z']);
$builder->order('age', EnumSort::DESC);
$builder->addOrder('name', EnumSort::ASC);

$builder->run();
// Will return an array of added objects
```

If a collection has multiple indexes, builder use only the one of them that is better to search

Use `andWhere` to add new comparison or `where` to use from scratch.

```
$builder = $collection->createBuilder();

$builder->andWhere('name', EnumOperator::IsNull);

$builder->where('country', 'name', EnumOperator::Between, ['A','Z']);
// will search all in A..Z
```

Similar with order `addOrder` to add next order or `order` to replace all previous with a new one.

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ihor Fedan](https://github.com/assassin215k)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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.

###  Release Activity

Cadence

Every ~13 days

Total

3

Last Release

1557d ago

Major Versions

0.0.1 → v2.x-dev2022-02-08

PHP version history (2 changes)0.0.1PHP &gt;=8.0

v2.x-devPHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7cb2401d2ff21efc833cba966a4894a9878b219418684f8674494d42d3f4ec27?d=identicon)[assassin215k](/maintainers/assassin215k)

---

Top Contributors

[![assassin215k](https://avatars.githubusercontent.com/u/14086942?v=4)](https://github.com/assassin215k "assassin215k (5 commits)")

---

Tags

btreecollectionindexindexingphpcollectionindexbtree

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.0M34](/packages/phpcollection-phpcollection)[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.2k412.9k11](/packages/aimeos-map)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[loophp/collection

A (memory) friendly, easy, lazy and modular collection class.

745663.8k13](/packages/loophp-collection)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)

PHPackages © 2026

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