承接 dan-on/php-interval-tree 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dan-on/php-interval-tree

Composer 安装命令:

composer require dan-on/php-interval-tree

包简介

Is an implementation of interval binary search tree according to Thomas Cormen book "Introduction to Algorithms".

README 文档

README

Latest Stable Version Total Downloads License PHP Version Require

Overview

Package dan-on/php-interval-tree is an implementation of self balancing binary search tree data structure called Red-Black Tree.

Based on interval tree described in "Introduction to Algorithms 3rd Edition", published by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein.

Complexity

Operation Best, Average, Worst
Insertion O(log(n))
Search O(log(n))
Remove O(log(n))
Space O(n)

Installing via Composer

composer require dan-on/php-interval-tree

Usage

Interval Tree

insert(IntervalInterface $interval, mixed $value): void

Insert new pair (interval + value) into interval tree

use Danon\IntervalTree\IntervalTree;

$tree = new IntervalTree();
$tree->insert(new NumericInterval(1, 10), 'val1');
$tree->insert(new NumericInterval(2, 5), 'val2');
$tree->insert(new NumericInterval(11, 12), 'val3');

findIntersections(IntervalInterface $interval): Iterator<Pair>

Find pairs which intervals intersect with given interval

$intersections = $tree->findIntersections(new NumericInterval(3, 5));
foreach($intersections as $pair) {
    $pair->getInterval()->getLow(); // 1, 2
    $pair->getInterval()->getHigh(); // 10, 5
    $pair->getValue(); // 'val1', 'val2'
}

hasIntersection(IntervalInterface $interval): bool

Returns true if interval has at least one intersection in tree

$tree->hasIntersection(new NumericInterval(3, 5)); // true

countIntersections(IntervalInterface $interval): int

Count intersections given interval in tree

$tree->countIntersections(new NumericInterval(3, 5)); // 2

remove(IntervalInterface $interval, $value): bool

Remove node from tree by interval and value

$tree->remove(new NumericInterval(11, 12), 'val3'); // true

exist(IntervalInterface $interval, $value): bool

Returns true if interval and value exist in the tree

$tree->exists(new NumericInterval(11, 12), 'val3'); // true

isEmpty(): bool

Returns true if tree is empty

$tree->isEmpty(); // false

getSize(): int

Get number of items stored in the interval tree

$tree->getSize(); // 3

Intervals

There are numeric and DateTimeInterface-based interval types included.

Numeric interval

use Danon\IntervalTree\Interval\NumericInterval;

// Instantiate numeric interval from array
$numericInterval = NumericInterval::fromArray([1, 100]);

// Instantiate numeric interval with constructor
$numericInterval = new NumericInterval(1, 100);

DateTime interval

use Danon\IntervalTree\Interval\DateTimeInterval;

// Instantiate DateTime interval from array
$dateTimeInterval = DateTimeInterval::fromArray([
    new DateTimeImmutable('2021-01-01 00:00:00'),
    new DateTimeImmutable('2021-01-02 00:00:00'),
]);

// Instantiate DateTime interval with constructor
$dateTimeInterval = new DateTimeInterval(
    new DateTimeImmutable('2021-01-01 00:00:00'), 
    new DateTimeImmutable('2021-01-02 00:00:00')
);

Tests

./vendor/bin/phpunit

dan-on/php-interval-tree 适用场景与选型建议

dan-on/php-interval-tree 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.2k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2020 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dan-on/php-interval-tree 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dan-on/php-interval-tree 我们能提供哪些服务?
定制开发 / 二次开发

基于 dan-on/php-interval-tree 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 15
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-11