f1r3starter/kdtree
Composer 安装命令:
composer require f1r3starter/kdtree
包简介
Yet another K-d tree implementation
README 文档
README
This is basic implementation of K-D trees in PHP inspired by Princeton K-D trees assignment and done as a graduation project for Algorithms Course in Projector.
Installation
composer require f1r3starter/kdtree
Usage
Tree construction
Firstly, you have to decide, how many dimensions your tree is going to be used for, after that you can add some points:
<?php use KDTree\Structure\KDTree; use KDTree\ValueObject\Point; $kdTree = new KDTree(2); // 2 for two-dimensional points, eg cities $kdTree->put(new Point(35.0844, 106.6504)); $kdTree->put(new Point(41.2865, 174.7762)); // if you need somehow connect point to your application, you can use setName method $point = new Point(46.8117, 33.4902); $point->setName('Kakhovka'); $kdTree->put($point); //... $points = $kdTree->points(); // returns list of all points, which can be iterated through $kdTree->contains(new Point(46.8117, 33.4902)); // will return "true"
Nearest point search
After tree is constructed, we can try to find nearest point:
<?php use KDTree\Search\NearestSearch; use KDTree\ValueObject\Point; $search = new NearestSearch($kdTree); $nearestPoint = $search->nearest((new Point(41.2865, 174.7762)));
Range search
Also there is an ability to find points in some particular range, which should have $2^{k}$ points, where k - is number dimensions in your K-D tree.
<?php use KDTree\Structure\PointsList; use KDTree\Search\PartitionSearch; use KDTree\ValueObject\{Partition, Point}; $pointsList = new PointsList(2); $pointsList->addPoint(new Point(46.8117, 33.4902)); $pointsList->addPoint(new Point(31.3142, 42.5245)); $pointsList->addPoint(new Point(22.2525, 41.3412)); $pointsList->addPoint(new Point(55.4245, 52.5134)); $search = new PartitionSearch($kdTree); $foundPoints = $search->find(new Partition($pointsList));
Demo
Demo is available in this repository.
Credits
f1r3starter/kdtree 适用场景与选型建议
f1r3starter/kdtree 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 12 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 f1r3starter/kdtree 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 f1r3starter/kdtree 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-18