rstoetter/cbalancedbinarytree-php
Composer 安装命令:
composer require rstoetter/cbalancedbinarytree-php
包简介
The repository rstoetter\cbalancedbinarytree-php implements the class cBalancedBinaryTree in PHP which is a balanced binary tree.
README 文档
README
The repository rstoetter\cbalancedbinarytree-php implements the class cBalancedBinaryTree in PHP which is a balanced binary tree.
You will need PHP 7 or later to use this repository
The class cBalancedBinaryTree consists of nodes of the type cBalancedBinaryTreeNode. You provide a class which holds the data part, a class subclassing cBalancedTreeNode, which manages the class with the data and a class subclassing cBalancedBinaryTree, which handles the class, which was subclassed from cBalancedBinaryTreeNode.
You need to know how to sort the Tree as you have to provide a unique key for each node, too. You could implement a method GetKey( ) in the class providing the data part to calculate such an unique key on the data it is holding.
An Example would be:
class cMyTreeData { public $m_data_1 = ''; public $m_data_2 = -1; function __construct( string $data_1, int $data_2 ){ $this->m_data_1 = $data_1; $this->m_data_1 = $data_2; } // function __construct( ) public function GetKey( ) : string { // calculate the unique sort key for the Tree return "{$this->m_data_1}-{$this->m_data_2}"; } // function GetKey( ) // other methods here } // class cMyTreeData class cMyTreeNode extends \rstoetter\cbalancedbinarytree\cBalancedBinaryTreeNode { function __construct( string $data_1, int $data_2 ){ $obj_data = new cMyTreeData( $data_1, $data_2 ); parent::__construct( $obj_data->GetKey( ), $obj_data ); } // function __construct( ) public function __toString( ) : string { $ret = $this->_data->GetKey(); return $ret; } // function __toString( ) } // class cMyTreeNode class cMyTree extends \rstoetter\cbalancedbinarytree\cBalancedBinaryTree { function __construct( ){ // do something here // $this->RebalanceTree( ); } // function __construct( ) public function MyInsert( string $data_1, int $data_2 ) { // inserts a new node in the tree $obj_new = new cMyTreeNode( $data_1, $data_2 ); $this->InsertNode( $obj_new ); // maybe you have to rebalance the tree now // NOTE: if you are filling the tree with a bunch of data, then you can rebalance the tree after reading all objects, too $this->RebalanceTree( ); } // function MyInsert( ) public function MySearch( string $key ) { // returns an object of type cMyTreeData or false $obj_found = $this->SearchByKey( $key ); // $obj_found is of type cBalancedBinaryTreeNode if ( $obj_found !== false ) { return $obj_found->GetData( ); } return false; } // function MySearch( ) public function PrintTree( ) : string { // return the ordered keys of the Tree as a string parent::_PrintTree( $this->m_root ); } // function PrintTree( ) protected function _TraverseInOrder( $tree ) { // internal method to recurse the tree in order beginning with $tree and do something with each node if ( is_null( $tree ) ) { return ; } // $this->_TraverseInOrder( $tree->GetLeft( ) ); // $obj = $tree->GetData( ); // // do something with $obj, which is of the type cMyTreeData // // $this->_TraverseInOrder( $tree->GetRight( ) ); } // function _TraverseInOrder( ) public function TraverseInOrder( ) { // traverse the whole tree in ordered order // recurse the tree beginning with the root pointer $this->_TraverseInOrder( $this->m_root ); } // function TraverseInOrder( ) } // class cMyTree $my_tree = new cMyTree( ); $my_tree->MyInsert( 'data 1', 1 ); $my_tree->MyInsert( 'data 2', 2 ); $my_tree->MyInsert( 'data 3', 3 ); $obj = $my_tree->MySearch( 'data 1' ); if ( $obj !== false ) { // do something withe $obj }
Installation
This project assumes you have composer installed. Simply add:
"require" : {
"rstoetter/cbalancedbinarytree-php" : ">=1.0.0"
}
to your composer.json, and then you can simply install with:
composer install
More information
See the project wiki for more information.
rstoetter/cbalancedbinarytree-php 适用场景与选型建议
rstoetter/cbalancedbinarytree-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「tree」 「class」 「binary」 「balanced」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rstoetter/cbalancedbinarytree-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rstoetter/cbalancedbinarytree-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rstoetter/cbalancedbinarytree-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
jsTree widget for yii2
Collection of methods that I or you usually use.
A very simple yet useful helper class to handle PHP file uploads.
Doctrine2 behavior traits - slowhop fork
A fast and dynamic Merkle tree implementation
Yii2 js base class
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-25