承接 loophp/phptree 相关项目开发

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

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

loophp/phptree

Composer 安装命令:

composer require loophp/phptree

包简介

An implementation of tree data structure

README 文档

README

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Scrutinizer code quality Type Coverage Code Coverage Mutation testing badge License Donate!

PhpTree

Description

A PHP implementation of tree data structure.

It provides different trees implementations:

  • Node: The base class.
  • N-ary node: (or K-ary tree) extends the base class and allows you to specify the capacity of a node, the maximum children a node can have.
  • Value node: extends the N-ary node and allows you to attach a value to the node.
  • KeyValue node: extends the Value node and allows you to attach a key and a value to the node.
  • Trie node: extends the KeyValue node, a simple Trie tree.
  • Auto-balanced node: extends the N-ary node and tries to keep the tree as symetric as possible. It automatically balance all the children as soon as they are added.
  • Merkle node: a tree in which every non-leaf node is labelled with the cryptographic hash of the labels of its child nodes.

4 trees traversal algorithms:

  • In order
  • Post order
  • Pre order
  • Breadth first

Exporters and importers:

  • Ascii: Export a tree into an ascii graphic, just for swag and visualisation fun.
  • Graph: Export a tree into a Graph using the graphp/graphp library.
  • GraphViz: Export a tree into a script in GraphViz format.
  • Text: Export a tree into a simple string, easy for storing in a database.
  • nikic/php-ast: Import a tree from an AST generated by the PHP extension AST.
  • nikic/php-parser: Import a tree from an AST generated by nikic/php-parser.
  • microsoft/tolerant-php-parser: Import a tree from an AST generated by microsoft/tolerant-php-parser.

Modifier:

  • Reverse: To reverse a tree, all the children are mirrored.

Documentation

Blog post: https://not-a-number.io/2018/phptree-a-fast-tree-implementation

Changelog

See CHANGELOG.MD

Requirements

  • PHP >= 7.1

Installation

composer require loophp/phptree

Optional packages

  • drupol/launcher: To automatically open a resource using the proper application on your operating system.
  • graphp/graphp: To export a tree into a Graph.

Usage

<?php

declare(strict_types = 1);

use loophp\phptree\Exporter\Gv;
use loophp\phptree\Exporter\Image;
use loophp\phptree\Node\ValueNode;
use loophp\phptree\Exporter\Text;
use loophp\launcher\Launcher;

include './vendor/autoload.php';

// Create the root node.
$tree = new ValueNode('root', 2);

$nodes = [];
foreach (\range('A', 'Z') as $v) {
    $nodes[] = new ValueNode($v, 2);
}

// Add children to the root node.
$tree->add(...$nodes);

// Export to text.
$textExporter = new Text();
$textExporter->export($tree); // [root[A[C[G[O][P]][H[Q][R]]][D[I[S][T]][J[U][V]]]][B[E[K[W][X]][L[Y][Z]]][F[M][N]]]]⏎

// Export to a GraphViz script with the Gv exporter
$graphvizExporter = new Gv();
$dotScript = $graphvizExporter->export($tree);
file_put_contents('tree.dot', $dotScript);
// Then do "dot -Tsvg tree.dot -o tree.svg" to export in SVG.

// Or use the Image exporter that does it for you.
$imageExporter = new Image();
$imageContent = $imageExporter->setFormat('png')->export($tree);
file_put_contents('tree.png', $imageContent);

// If you want to launch the image, you can use an optional package.
// do: composer require drupol/launcher
// then:
Launcher::open('tree.png');

Code quality, tests and benchmarks

Every time changes are introduced into the library, Github run the tests and the benchmarks.

The library has tests written with PHPSpec. Feel free to check them out in the spec directory. Run composer phpspec to trigger the tests.

Before each commit some inspections are executed with GrumPHP, run ./vendor/bin/grumphp run to check manually.

PHPBench is used to benchmark the library, to run the benchmarks: composer bench

PHPInfection is used to ensure that your code is properly tested, run composer infection to test your code.

Contributing

Feel free to contribute by sending pull requests. We are a usually very responsive team and we will help you going through your pull request from the beginning to the end.

For some reasons, if you can't contribute to the code and willing to help, sponsoring is a good, sound and safe way to show us some gratitude for the hours we invested in this package.

Sponsor me on Github and/or any of the contributors.

Changelog

See CHANGELOG.md for a changelog based on git commits.

For more detailed changelogs, please check the release changelogs.

loophp/phptree 适用场景与选型建议

loophp/phptree 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.77M 次下载、GitHub Stars 达 98, 最近一次更新时间为 2020 年 01 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「tree」 「data structure」 「binary tree」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 loophp/phptree 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.77M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 98
  • 点击次数: 23
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 98
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

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