Skip to content

Commit a84e899

Browse files
committed
JRuby, MRI 1.8.7, Rubinius compatability
1 parent 9c4ce1c commit a84e899

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

.rspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
--color
2-
--format documentation
2+
--format progress

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ ip_tree.find_first(client_ip).value # => {:city=>"YEKT"}
6767
## TODO
6868
1. Fix README typos and grammatical errors (english speaking contributors are welcomed)
6969
2. Implement C binding for MRI.
70-
3. Test on different versions of Ruby.
7170

7271
## LICENSE
7372
Copyright (c) 2012 Alexei Mikhailov

benchmark/benchmark.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env ruby
2+
require "rubygems"
23
require "bundler/setup"
34
require "benchmark"
45
require "segment_tree"
@@ -42,6 +43,6 @@ def list(n)
4243
tests.each do |n|
4344
data = lists[n]
4445

45-
x.report(n.to_s) { data.find { |range, _| range.cover?(rand(n)) } }
46+
x.report(n.to_s) { data.find { |range, _| range.include?(rand(n)) } }
4647
end
4748
end

lib/segment_tree.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
require "forwardable"
2-
require "segment_tree/version"
32

43
class SegmentTree
54
# An abstract tree node
65
class Node #:nodoc:all:
76
extend Forwardable
8-
def_delegators :@range, :cover?, :begin, :end
7+
def_delegators :@range, :include?, :begin, :end
98
end
109

1110
# An elementary intervals or nodes container
@@ -24,14 +23,14 @@ def initialize(left, right)
2423
# Find all intervals containing point +x+ within node's children. Returns array
2524
def find(x)
2625
[@left, @right].compact.
27-
select { |node| node.cover?(x) }.
26+
select { |node| node.include?(x) }.
2827
map { |node| node.find(x) }.
2928
flatten
3029
end
3130

3231
# Find first interval containing point +x+ within node's children
3332
def find_first(x)
34-
subset = [@left, @right].compact.find { |node| node.cover?(x) }
33+
subset = [@left, @right].compact.find { |node| node.include?(x) }
3534
subset && subset.find_first(x)
3635
end
3736

@@ -56,7 +55,7 @@ def find(x)
5655
end
5756

5857
def find_first(x)
59-
cover?(x) ? self : nil
58+
include?(x) ? self : nil
6059
end
6160
end
6261

lib/segment_tree/version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class SegmentTree
2-
VERSION = "0.0.1"
3-
end
2+
VERSION = "0.0.2"
3+
end

segment_tree.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
88
gem.summary = %q{Tree data structure for storing segments. It allows querying which of the stored segments contain a given point.}
99
gem.homepage = "https://github.com/take-five/segment_tree"
1010

11-
gem.files = `git ls-files`.split($\)
12-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
11+
gem.files = `git ls-files`.split($\).grep(/lib|spec/)
12+
gem.test_files = gem.files.grep(/spec/)
1313
gem.name = "segment_tree"
1414
gem.require_paths = %W(lib)
1515
gem.version = SegmentTree::VERSION

spec/spec_helper.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "bundler/setup"
2-
require "simplecov"
32

43
RSpec.configure do |config|
54
# Run specs in random order to surface order dependencies. If you find an
@@ -9,4 +8,9 @@
98
config.order = 'random'
109
end
1110

12-
SimpleCov.start
11+
if defined?(RUBY_ENGINE) &&
12+
RUBY_ENGINE == "ruby" &&
13+
RUBY_VERSION > "1.9"
14+
require "simplecov"
15+
SimpleCov.start
16+
end

0 commit comments

Comments
 (0)