PHPackages                             swango/segment\_tree - 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. swango/segment\_tree

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

swango/segment\_tree
====================

1.1.1(1y ago)0479↓33.3%Apache-2.0PHPPHP &gt;=7.1

Since Sep 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/swangoframework/swango-segment_tree)[ Packagist](https://packagist.org/packages/swango/segment_tree)[ RSS](/packages/swango-segment-tree/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

Swango\\SegmentTree
===================

[](#swangosegmenttree)

[![Php Version](https://camo.githubusercontent.com/c197ef1e57a32c886b2a54d02ead7dbc035f18b3f39a642703b9372eef7819f9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e312d627269676874677265656e2e7376673f6d61784167653d32353932303030)](https://secure.php.net/)[![SegmentTree License](https://camo.githubusercontent.com/1c419f89412ea6c234c184ad6d85decb127c18584858d3707ae7d8e2131eccc4/68747470733a2f2f696d672e736869656c64732e696f2f686578706d2f6c2f706c75672e7376673f6d61784167653d32353932303030)](https://github.com/swlib/archer/blob/master/LICENSE)

Easy segment tree in PHP. Support multi key-value storage. Written without any global variable. Can be used in all kinds of environment.

### Common segment tree

[](#common-segment-tree)

```
$tree = Swango\SegmentTree\Tree\Common::newTree(0,100000); // Create a tree with scale of 0~100000;

// Set to use "==" when comparing values. Two objects of different instances that have same content will be considered equal.
$tree->useDoubleEqualSign();
// Set to use "===" when comparing values. Two objects of different instances will be considered not equal no matter their content.
$tree->useTripleEqualSign();

// Accept all kinds of values including string, number, null, bool, array, object, etc.
$tree->setValue(100, 1000, 'key1', 123);
$tree->setValue(20000, 20400, 'key1', null);
$tree->setValue(21000, 30000, 'key1', false);
$tree->setValue(20005, 21005, 'key1', [1, 2, 3]);
$tree->setValue(50000, 60000, 'key2', new \SplQueue());
$tree->setValue(99999, 100000, 'key3', 'some value');

// Get value of certain position.
var_dump($tree->getValue(20006, 'key1'));

// Delete value of between certain positions.
$tree->delValue(30000, 100000, 'key1');

// Throws exception when value not found.
var_dump($tree->getValue(70000, 'key1'));

// Get segment arrays.
var_dump($tree->getSegmentsOfGivenKey('key1'));
var_dump($tree->getSegmentsOfGivenKeyAndValue('key1', [1, 2, 3]));

// Remove all redundant nodes in the tree to reduce memory cost.
$tree->optimize();

// Clear all values and child nodes and make it a new tree.
$tree->clear();
```

### Version compressed segment tree

[](#version-compressed-segment-tree)

```
$tree = Swango\SegmentTree\Tree\Version::newTree(
    '1.0.0', '1.0.1', '1.0.2', '1.0.3', '1.1.0', '1.4.1', '2.0.0', '2.0.1-RC1', '3.0.0'
); // Create a tree with versions. These versions will be sorted using version_compare() and remove all duplicated

// All methods are similar with Common tree.
$tree->setValue('1.0.2', '2.0.0', 'key1', true);
var_dump($tree->getValue('1.1.0'));
```

### Date compressed segment tree

[](#date-compressed-segment-tree)

```
$tree = Swango\SegmentTree\Tree\Date::newTree(
    '2020-09-25', '2020-12-12'
); // Create a tree with dates.

// All methods are similar with Common tree.
$tree->setValue('2020-09-29', '2020-11-11', 'key1', true);
var_dump($tree->getValue('2020-11-01'));
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance48

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~1022 days

Total

3

Last Release

386d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9639344?v=4)[烈梦](/maintainers/fdreamsu)[@fdreamsu](https://github.com/fdreamsu)

---

Top Contributors

[![fdreamsu](https://avatars.githubusercontent.com/u/9639344?v=4)](https://github.com/fdreamsu "fdreamsu (13 commits)")

---

Tags

phpsegment-treeversion-managerphpsegment-tree

### Embed Badge

![Health badge](/badges/swango-segment-tree/health.svg)

```
[![Health](https://phpackages.com/badges/swango-segment-tree/health.svg)](https://phpackages.com/packages/swango-segment-tree)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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