Skip to content

Commit a4a5797

Browse files
authored
prep for 0.5 (#8)
* wip * wip * wip * wip * wip * wip
1 parent 92c9c58 commit a4a5797

File tree

12 files changed

+275
-156
lines changed

12 files changed

+275
-156
lines changed

.github/workflows/ci.yml

-16
This file was deleted.

.github/workflows/test.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: test
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
strategy:
8+
max-parallel: 3
9+
matrix:
10+
os: [macos, ubuntu]
11+
ruby: [3.0, 3.4]
12+
runs-on: ${{ matrix.os }}-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: taiki-e/install-action@just
16+
- uses: ruby/setup-ruby@v1
17+
with:
18+
bundler-cache: true
19+
ruby-version: ${{ matrix.ruby }}
20+
- run: just ci

.gitignore

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
*.gem
2-
.ruby-version
3-
Gemfile.lock
4-
lib/*.so
5-
lib/kdtree.bundle
6-
tmp
1+
*.bundle
2+
*.so
3+
/.tool-versions
4+
/Gemfile.lock
5+
/pkg/
6+
/tmp/

.rubocop.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
require:
2+
- standard
3+
4+
inherit_gem:
5+
standard: config/ruby-3.3.yml
6+
standard-custom: config/base.yml
7+
standard-performance: config/base.yml
8+
9+
plugins:
10+
- standard-custom
11+
- standard-performance
12+
- rubocop-performance
13+
14+
AllCops:
15+
NewCops: enable
16+
SuggestExtensions: false
17+
18+
#
19+
# fight with standardrb!
20+
#
21+
22+
# we like these, don't remove
23+
Bundler/OrderedGems: { Enabled: true } # sort gems in gemfile
24+
Bundler/GemVersion: { Enabled: true } # make sure we have versions
25+
Layout/EmptyLineBetweenDefs: { AllowAdjacentOneLineDefs: true }
26+
Lint/NonLocalExitFromIterator: { Enabled: false }
27+
Lint/RedundantDirGlobSort: { Enabled: true } # glob is already sorted
28+
Performance/RegexpMatch: { Enabled: false }
29+
Style/HashSyntax: { EnforcedShorthandSyntax: always } # use modern hash syntax
30+
Style/NestedTernaryOperator: { Enabled: false } # we do this sometimes
31+
Style/NonNilCheck: { Enabled: false } # allow x != nil for clarity
32+
Style/RedundantAssignment: { Enabled: false } # allows s=xxx;s=yyy;s
33+
Style/RedundantReturn: { Enabled: false } # sometines we do this while working on something
34+
Style/StringConcatenation: { Enabled: true } # prefer interpolation
35+
Style/TrailingCommaInArrayLiteral: { EnforcedStyleForMultiline: consistent_comma } # commas!!
36+
Style/TrailingCommaInHashLiteral: { EnforcedStyleForMultiline: consistent_comma } # commas!!
37+
38+
#
39+
# These are rules that are not enabled by default (in standardrb) but we tend to
40+
# write code this way. We don't often trigger these, but it matches our style.
41+
#
42+
43+
Lint/MissingSuper: { Enabled: true }
44+
Naming/FileName: { Enabled: true }
45+
Naming/MemoizedInstanceVariableName: { Enabled: true }
46+
Naming/MethodName: { Enabled: true }
47+
Performance/MapCompact: { Enabled: true }
48+
Performance/SelectMap: { Enabled: true }
49+
Style/BlockDelimiters: { Enabled: true }
50+
Style/CollectionCompact: { Enabled: true }
51+
Style/CollectionMethods: { Enabled: true }
52+
Style/HashEachMethods: { Enabled: true }
53+
Style/HashTransformKeys: { Enabled: true }
54+
Style/HashTransformValues: { Enabled: true }
55+
Style/MinMax: { Enabled: true }
56+
Style/PreferredHashMethods: { Enabled: true }
57+
Style/SelectByRegexp: { Enabled: true }
58+
Style/SymbolArray: { Enabled: true }
59+
Style/WordArray: { Enabled: true }

Gemfile

+7
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
source "http://rubygems.org"
22
gemspec
3+
4+
group :development, :test do
5+
gem "minitest", "~> 5.25"
6+
gem "rake", "~> 13.2"
7+
gem "rake-compiler", "~> 1.3"
8+
gem "standard", "~> 1.49", require: false, platform: :mri
9+
end

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012 Adam Doppelt
1+
Copyright (c) 2025 Adam Doppelt
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
## Kdtree
1+
## Kdtree [![test](https://github.com/gurgeous/kdtree/actions/workflows/test.yml/badge.svg)](https://github.com/gurgeous/kdtree/actions/workflows/test.yml)
22

3-
[![Build Status](https://github.com/gurgeous/kdtree/workflows/ci/badge.svg?branch=master)](https://github.com/gurgeous/kdtree/actions)
43

54
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.
65

76
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.
87

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).
109

11-
Note: kdtree 0.3 obsoletes these forks: ghazel-kdtree, groupon-kdtree, tupalo-kdree. Thanks guys!
10+
Note: kdtree obsoletes these forks: ghazel-kdtree, groupon-kdtree, tupalo-kdree. Thanks guys!
1211

13-
### Usage
12+
### Installation
1413

15-
First, install kdtree:
14+
```ruby
15+
# install gem
16+
$ gem install kdtree
1617

17-
```sh
18-
$ sudo gem install kdtree
18+
# or add to your Gemfile
19+
gem "kdtree"
1920
```
2021

22+
### Usage
23+
2124
It's easy to use:
2225

2326
- **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**.
@@ -50,17 +53,17 @@ kd2 = File.open("treefile") { |f| Kdtree.new(f) }
5053

5154
### Performance
5255

53-
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:
5457

5558
```
56-
build (init) 3.52s
57-
nearest point 0.000003s
58-
nearest 5 points 0.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 points 0.000006s
66+
nearest 255 points 0.000026s
6467
```
6568

6669
### Limitations
@@ -81,9 +84,16 @@ Since this gem was originally released, several folks have contributed important
8184

8285
### Changelog
8386

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!
88+
89+
#### 0.5 - May 2025
90+
91+
- justfile
92+
- hygiene - updated deps, format/lint, modernize rakefile
93+
- moved to ruby 3.x or higher, tested with ruby 3.4
94+
- updated benchmark numbers (still real fast)
8595

86-
#### 0.4 - current
96+
#### 0.4 - Mar 2017
8797

8898
- this is mostly housekeeping - test on more rubies, fix a few warnings
8999

Rakefile

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
1-
require "bundler/setup"
1+
require "bundler/gem_tasks"
22
require "rake/extensiontask"
33
require "rake/testtask"
44

5-
# load the spec, we use it below
6-
spec = Gem::Specification.load("kdtree.gemspec")
7-
8-
#
9-
# gem
10-
#
11-
12-
task :build do
13-
system "gem build --quiet kdtree.gemspec"
14-
end
15-
16-
task install: :build do
17-
system "sudo gem install --quiet kdtree-#{spec.version}.gem"
18-
end
19-
20-
task release: :build do
21-
system "git tag -a #{spec.version} -m 'Tagging #{spec.version}'"
22-
system "git push --tags"
23-
system "gem push kdtree-#{spec.version}.gem"
24-
end
25-
26-
#
27-
# rake-compiler
28-
#
29-
30-
Rake::ExtensionTask.new("kdtree", spec)
31-
32-
33-
#
34-
# testing
35-
#
5+
Rake::ExtensionTask.new("kdtree")
6+
task test: :compile
367

37-
Rake::TestTask.new(:test) do |test|
38-
test.libs << "test"
8+
Rake::TestTask.new do
9+
_1.libs << "test"
10+
_1.test_files = FileList["test/**/test_*.rb"]
3911
end
40-
task test: :compile
4112
task default: :test

0 commit comments

Comments
 (0)