KDTree
KDTree is a Ruby wrapper for John Tsiombikas' KDTree library written in C. It supports K dimensional tree nearest neighbor searches.
Installation
Add this line to your application's Gemfile:
gem 'kd_tree'
And then execute:
$ bundle
Or install it yourself as:
$ gem install kd_tree
Usage
Iniitalize a new KDTree with a multi-dimensional array of nodes, and an integer specifying how many dimensions each node has:
tree = KDTree.new([ [1, 2, 3], [ 4, 5, 6] ], 3)
Insert additional nodes:
tree.insert([7, 8, 9])
Perform a nearest neighbor search:
tree.nearest_neighbor([ 1, 2, 3 ])
tree.nearest_neighbor([ 4, 5, 6])
tree.nearest_neigbor([ 100, 101, 102 ])
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request