2017 © Pedro Peláez
 

library kdtree

file system KDTree index

image

hexogen/kdtree

file system KDTree index

  • Wednesday, June 6, 2018
  • by hexogen
  • Repository
  • 1 Watchers
  • 7 Stars
  • 608 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 236 % Grown

The README.md

K-D Tree

Latest Version on Packagist [![Build Status][ico-tests]][link-tests] codecov ![Software License][ico-license] Total Downloads, (*1)

PHP multidimensional K-D Tree implementation., (*2)

To receive all benefits from K-D Tree, use file system implementation(FSKDTree). FSKDTree stores tree in binary format and uses lazy loading while traversing through nodes. Current approach provides much higher performance compared to deserialization., (*3)

Install

Via Composer, (*4)

``` bash $ composer require hexogen/kdtree, (*5)


## Usage ### Tree creation ``` php //Item container with 2 dimensional points $itemList = new ItemList(2); //Adding 2 - dimension items to the list $itemList->addItem(new Item(1, [1.2, 4.3])); $itemList->addItem(new Item(2, [1.3, 3.4])); $itemList->addItem(new Item(3, [4.5, 1.2])); $itemList->addItem(new Item(4, [5.2, 3.5])); $itemList->addItem(new Item(5, [2.1, 3.6])); //Building tree with given item list $tree = new KDTree($itemList);

Searching nearest items to the given point

``` php //Creating search engine with custom algorithm (currently Nearest Search) $searcher = new NearestSearch($tree);, (*6)

//Retrieving a result ItemInterface[] array with given size (currently 2) $result = $searcher->search(new Point([1.25, 3.5]), 2);, (*7)

echo $result[0]->getId(); // 2 echo $result[0]->getNthDimension(0); // 1.3 echo $result[0]->getNthDimension(1); // 3.4, (*8)

echo $result[1]->getId(); // 1 echo $result[1]->getNthDimension(0); // 1.2 echo $result[1]->getNthDimension(1); // 4.3, (*9)


### Persist tree to a binary file ``` php //Init tree writer $persister = new FSTreePersister('/path/to/dir'); //Save the tree to /path/to/dir/treeName.bin $persister->convert($tree, 'treeName.bin');

File system version of the tree

``` php //ItemInterface factory $itemFactory = new ItemFactory();, (*10)

//Then init new instance of file system version of the tree $fsTree = new FSKDTree('/path/to/dir/treeName.bin', $itemFactory);, (*11)

//Now use fs kdtree to search $fsSearcher = new NearestSearch($fsTree);, (*12)

//Retrieving a result ItemInterface[] array with given size (currently 2) $result = $fsSearcher->search(new Point([1.25, 3.5]), 2);, (*13)

echo $result[0]->getId(); // 2 echo $result[1]->getId(); // 1, (*14)


## Change log Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Testing ``` bash $ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*15)

Security

If you discover any security related issues, please email volodymyrbas@gmail.com instead of using the issue tracker., (*16)

Credits

License

The MIT License (MIT). Please see License File for more information., (*17)

The Versions

06/06 2018

dev-master

9999999-dev https://github.com/hexogen/kdtree

file system KDTree index

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

kdtree hexogen

10/01 2017

0.1.0

0.1.0.0 https://github.com/hexogen/kdtree

file system KDTree index

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

kdtree hexogen