You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A kd tree is a data structure that recursively partitions the world in order to rapidly answer nearest neighbor queries. A generic kd tree can support any number of dimensions, and can return either the nearest neighbor or a set of N nearest neighbors.
6
5
7
6
This gem is a blazingly fast, native, 2d kdtree. It's specifically built to find the nearest neighbor when searching millions of points. It's used in production at Urbanspoon and several other companies.
8
7
9
-
The first version of this gem was released back in 2009. See the original [blog post](http://gurge.com/2009/10/22/ruby-nearest-neighbor-fast-kdtree-gem/) for the full story. Wikipedia has a great [article on kdtrees](http://en.wikipedia.org/wiki/K-d_tree).
8
+
The first version of this gem was released back in 2009. Wikipedia has a great [article on kdtrees](http://en.wikipedia.org/wiki/K-d_tree).
Note: kdtree obsoletes these forks: ghazel-kdtree, groupon-kdtree, tupalo-kdree. Thanks guys!
12
11
13
-
### Usage
12
+
### Installation
14
13
15
-
First, install kdtree:
14
+
```ruby
15
+
# install gem
16
+
$ gem install kdtree
16
17
17
-
```sh
18
-
$ sudo gem install kdtree
18
+
# or add to your Gemfile
19
+
gem "kdtree"
19
20
```
20
21
22
+
### Usage
23
+
21
24
It's easy to use:
22
25
23
26
-**Kdtree.new(points)** - construct a new tree. Each point should be of the form `[x, y, id]`, where `x/y` are floats and `id` is an int. Not a string, not an object, **just an int**.
Kdtree is fast. How fast? Using a tree with 1 million points on my i5 2.8ghz:
56
+
Kdtree is fast. How fast? Using a tree with 1 million points on my M1:
54
57
55
58
```
56
-
build (init) 3.52s
57
-
nearest point0.000003s
58
-
nearest 5 points0.000004s
59
-
nearest 50 points 0.000014s
60
-
nearest 255 points 0.000063s
61
-
62
-
persist 0.301963s
63
-
read (init) 0.432676s
59
+
build (init) 0.96s
60
+
persist 0.000814s
61
+
read (init) 0.009236s
62
+
63
+
nearest point 0.000002s
64
+
nearest 5 points 0.000002s
65
+
nearest 50 points0.000006s
66
+
nearest 255 points 0.000026s
64
67
```
65
68
66
69
### Limitations
@@ -81,9 +84,16 @@ Since this gem was originally released, several folks have contributed important
81
84
82
85
### Changelog
83
86
84
-
Note: This gem is stable, maintained and continues to work great with all modern versions of Ruby MRI. Our CI tests through Ruby 2.7. No need for new releases until something breaks!
87
+
Note: This gem is stable, maintained and continues to work great with all modern versions of Ruby MRI. Our CI tests through Ruby 3.4. No need for new releases until something breaks!
0 commit comments