k-tree 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.semver +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +109 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +66 -0
- data/Rakefile +63 -0
- data/k-tree.gemspec +75 -0
- data/lib/k-tree.rb +1 -0
- data/lib/k-tree/k-tree.rb +94 -0
- data/spec/k-tree_spec.rb +33 -0
- data/spec/spec_helper.rb +29 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a8cf49611f2c53dd4ed380506bcf8c98948fb2b
|
4
|
+
data.tar.gz: 4dcc63dfda7e2ec8a4f577e3d0bcf390419e45f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b8e9fab7f61d92665add4d09478a4307098c4f1059c2361dc130442cf7e4739592cb756c1191b672c3a15524345f11d5e5f42c5e073d3aea9117b160dcd0135
|
7
|
+
data.tar.gz: feebf590811450cb26e0596bf48d86bc7d69bd615c4ab76438febaeb1f59f894383cf865b1bd56c87e407fcaf129bfc2842669a5fac0caf1d9044deb5983b7b3
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.semver
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Add dependencies to develop your gem here.
|
4
|
+
# Include everything needed to run rake, tests, features, etc.
|
5
|
+
group :development do
|
6
|
+
gem "rspec", "~> 2"
|
7
|
+
gem "yard", "~> 0"
|
8
|
+
gem "rdoc", "~> 3"
|
9
|
+
gem "bundler", "~> 1"
|
10
|
+
gem "jeweler", "~> 2"
|
11
|
+
gem "simplecov", "~> 0"
|
12
|
+
gem 'semver', '~> 1'
|
13
|
+
gem 'guard-rspec', '~> 0'
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.6)
|
5
|
+
builder (3.2.2)
|
6
|
+
celluloid (0.16.0)
|
7
|
+
timers (~> 4.0.0)
|
8
|
+
coderay (1.1.0)
|
9
|
+
descendants_tracker (0.0.4)
|
10
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
docile (1.1.5)
|
13
|
+
faraday (0.9.0)
|
14
|
+
multipart-post (>= 1.2, < 3)
|
15
|
+
ffi (1.9.3)
|
16
|
+
formatador (0.2.5)
|
17
|
+
git (1.2.8)
|
18
|
+
github_api (0.12.1)
|
19
|
+
addressable (~> 2.3)
|
20
|
+
descendants_tracker (~> 0.0.4)
|
21
|
+
faraday (~> 0.8, < 0.10)
|
22
|
+
hashie (>= 3.2)
|
23
|
+
multi_json (>= 1.7.5, < 2.0)
|
24
|
+
nokogiri (~> 1.6.3)
|
25
|
+
oauth2
|
26
|
+
guard (2.6.1)
|
27
|
+
formatador (>= 0.2.4)
|
28
|
+
listen (~> 2.7)
|
29
|
+
lumberjack (~> 1.0)
|
30
|
+
pry (>= 0.9.12)
|
31
|
+
thor (>= 0.18.1)
|
32
|
+
guard-rspec (0.7.3)
|
33
|
+
guard (>= 0.10.0)
|
34
|
+
hashie (3.3.1)
|
35
|
+
highline (1.6.21)
|
36
|
+
hitimes (1.2.2)
|
37
|
+
jeweler (2.0.1)
|
38
|
+
builder
|
39
|
+
bundler (>= 1.0)
|
40
|
+
git (>= 1.2.5)
|
41
|
+
github_api
|
42
|
+
highline (>= 1.6.15)
|
43
|
+
nokogiri (>= 1.5.10)
|
44
|
+
rake
|
45
|
+
rdoc
|
46
|
+
json (1.8.1)
|
47
|
+
jwt (1.0.0)
|
48
|
+
listen (2.7.9)
|
49
|
+
celluloid (>= 0.15.2)
|
50
|
+
rb-fsevent (>= 0.9.3)
|
51
|
+
rb-inotify (>= 0.9)
|
52
|
+
lumberjack (1.0.9)
|
53
|
+
method_source (0.8.2)
|
54
|
+
mini_portile (0.6.0)
|
55
|
+
multi_json (1.10.1)
|
56
|
+
multi_xml (0.5.5)
|
57
|
+
multipart-post (2.0.0)
|
58
|
+
nokogiri (1.6.3.1)
|
59
|
+
mini_portile (= 0.6.0)
|
60
|
+
oauth2 (1.0.0)
|
61
|
+
faraday (>= 0.8, < 0.10)
|
62
|
+
jwt (~> 1.0)
|
63
|
+
multi_json (~> 1.3)
|
64
|
+
multi_xml (~> 0.5)
|
65
|
+
rack (~> 1.2)
|
66
|
+
pry (0.10.1)
|
67
|
+
coderay (~> 1.1.0)
|
68
|
+
method_source (~> 0.8.1)
|
69
|
+
slop (~> 3.4)
|
70
|
+
rack (1.5.2)
|
71
|
+
rake (10.3.2)
|
72
|
+
rb-fsevent (0.9.4)
|
73
|
+
rb-inotify (0.9.5)
|
74
|
+
ffi (>= 0.5.0)
|
75
|
+
rdoc (3.12.2)
|
76
|
+
json (~> 1.4)
|
77
|
+
rspec (2.99.0)
|
78
|
+
rspec-core (~> 2.99.0)
|
79
|
+
rspec-expectations (~> 2.99.0)
|
80
|
+
rspec-mocks (~> 2.99.0)
|
81
|
+
rspec-core (2.99.2)
|
82
|
+
rspec-expectations (2.99.2)
|
83
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
84
|
+
rspec-mocks (2.99.2)
|
85
|
+
semver (1.0.1)
|
86
|
+
simplecov (0.9.0)
|
87
|
+
docile (~> 1.1.0)
|
88
|
+
multi_json
|
89
|
+
simplecov-html (~> 0.8.0)
|
90
|
+
simplecov-html (0.8.0)
|
91
|
+
slop (3.6.0)
|
92
|
+
thor (0.19.1)
|
93
|
+
thread_safe (0.3.4)
|
94
|
+
timers (4.0.1)
|
95
|
+
hitimes
|
96
|
+
yard (0.8.7.4)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
ruby
|
100
|
+
|
101
|
+
DEPENDENCIES
|
102
|
+
bundler (~> 1)
|
103
|
+
guard-rspec (~> 0)
|
104
|
+
jeweler (~> 2)
|
105
|
+
rdoc (~> 3)
|
106
|
+
rspec (~> 2)
|
107
|
+
semver (~> 1)
|
108
|
+
simplecov (~> 0)
|
109
|
+
yard (~> 0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Fred Mitchell
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= K-Tree
|
2
|
+
|
3
|
+
K-Tree is a data structure that generalizes the notion of Quadtrees and
|
4
|
+
Octrees. The nodes subdivides the n-dimentional space into equal subsections
|
5
|
+
of 2^n k-tants (quadrants for 2-dimensional spaces, octants for 3-dimensional)
|
6
|
+
down to your desired level of resolution, and during the creation allows you
|
7
|
+
to decide whether or not to keep the child nodes based on your criteria
|
8
|
+
for whether or not there's enough variance.
|
9
|
+
|
10
|
+
The coordinats of the midpoint of all these sections are maintained by k-tree
|
11
|
+
and are therefore enumerable.
|
12
|
+
|
13
|
+
== Gem Version
|
14
|
+
{<img src="https://badge.fury.io/rb/k-tree.png" alt="Gem Version" />}[http://badge.fury.io/rb/k-tree]
|
15
|
+
|
16
|
+
== Usage
|
17
|
+
|
18
|
+
== Examples
|
19
|
+
|
20
|
+
For now, I will use the spec as example of usage. This is lame, I'll admit,
|
21
|
+
but I will improve this shortly.
|
22
|
+
|
23
|
+
require 'k-tree'
|
24
|
+
include KTree
|
25
|
+
|
26
|
+
let(:ktree) do
|
27
|
+
KTree.create do |node, vchildren|
|
28
|
+
rand(3) != 5
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "created a tree" do
|
33
|
+
expect(ktree).to_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has nodes" do
|
37
|
+
expect(ktree.root).to_not be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it "upper and lower coords are never equal" do
|
41
|
+
ktree.each do |node|
|
42
|
+
expect(node.upper).to_not eq node.lower
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
== Known Issues
|
48
|
+
Currently K-Tree does not support "nearest neighbor" queries, as this
|
49
|
+
is beyond the scope of the current needs of the author. Check out kd-tree
|
50
|
+
amd r-tree for that. Or feel free to add that functionality and do a pull request.
|
51
|
+
|
52
|
+
== Contributing to k-tree
|
53
|
+
|
54
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
55
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
56
|
+
* Fork the project.
|
57
|
+
* Start a feature/bugfix branch.
|
58
|
+
* Commit and push until you are happy with your contribution.
|
59
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
60
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
61
|
+
|
62
|
+
== Copyright
|
63
|
+
|
64
|
+
Copyright (c) 2014 Fred Mitchell. See LICENSE.txt for
|
65
|
+
further details.
|
66
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
require 'semver'
|
6
|
+
|
7
|
+
def s_version
|
8
|
+
SemVer.find.format "%M.%m.%p%s"
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:default, :development)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
$stderr.puts e.message
|
15
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
require 'rake'
|
19
|
+
|
20
|
+
require 'jeweler'
|
21
|
+
Jeweler::Tasks.new do |gem|
|
22
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
23
|
+
gem.name = "k-tree"
|
24
|
+
gem.homepage = "http://github.com/flajann2/k-tree"
|
25
|
+
gem.license = "MIT"
|
26
|
+
gem.summary = %Q{K-Tree is a generalization of quadtrees and octrees.}
|
27
|
+
gem.description = %Q{
|
28
|
+
This is a data structure to represent and manage k-trees,
|
29
|
+
primarily created for use in RubyNEAT, but may see other possible applications.
|
30
|
+
The goal here is to be roebust in the creation of your k-tree, to allow
|
31
|
+
you to prune during creation, since, especially for higher-dimensional trees,
|
32
|
+
the number of leaf node can become very large.
|
33
|
+
|
34
|
+
So a parent will have children nodes created down to the desired resolution,
|
35
|
+
and immediately after the creation of the children, will check to see if there's
|
36
|
+
enough variance among the children to keep them. If not, they are pruned immediately.
|
37
|
+
}
|
38
|
+
gem.email = "lordalveric@yahoo.com"
|
39
|
+
gem.authors = ["Fred Mitchell"]
|
40
|
+
gem.required_ruby_version = '>= 2.0'
|
41
|
+
gem.version = s_version
|
42
|
+
gem.files.exclude 'foo/**/*', 'rdoc/*',
|
43
|
+
'.idea/**/*', '.idea/**/.*', '.yardoc/**/*',
|
44
|
+
'Guardfile'
|
45
|
+
end
|
46
|
+
Jeweler::RubygemsDotOrgTasks.new
|
47
|
+
|
48
|
+
require 'rspec/core'
|
49
|
+
require 'rspec/core/rake_task'
|
50
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
51
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Code coverage detail"
|
55
|
+
task :simplecov do
|
56
|
+
ENV['COVERAGE'] = "true"
|
57
|
+
Rake::Task['spec'].execute
|
58
|
+
end
|
59
|
+
|
60
|
+
task :default => :spec
|
61
|
+
|
62
|
+
require 'yard'
|
63
|
+
YARD::Rake::YardocTask.new
|
data/k-tree.gemspec
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: k-tree 0.0.2 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "k-tree"
|
9
|
+
s.version = "0.0.2"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Fred Mitchell"]
|
14
|
+
s.date = "2014-09-15"
|
15
|
+
s.description = "\n This is a data structure to represent and manage k-trees,\n primarily created for use in RubyNEAT, but may see other possible applications.\n The goal here is to be roebust in the creation of your k-tree, to allow\n you to prune during creation, since, especially for higher-dimensional trees,\n the number of leaf node can become very large.\n\n So a parent will have children nodes created down to the desired resolution,\n and immediately after the creation of the children, will check to see if there's\n enough variance among the children to keep them. If not, they are pruned immediately.\n "
|
16
|
+
s.email = "lordalveric@yahoo.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
".semver",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.rdoc",
|
29
|
+
"Rakefile",
|
30
|
+
"k-tree.gemspec",
|
31
|
+
"lib/k-tree.rb",
|
32
|
+
"lib/k-tree/k-tree.rb",
|
33
|
+
"spec/k-tree_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/flajann2/k-tree"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.0")
|
39
|
+
s.rubygems_version = "2.2.2"
|
40
|
+
s.summary = "K-Tree is a generalization of quadtrees and octrees."
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 4
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<rspec>, ["~> 2"])
|
47
|
+
s.add_development_dependency(%q<yard>, ["~> 0"])
|
48
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2"])
|
51
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0"])
|
52
|
+
s.add_development_dependency(%q<semver>, ["~> 1"])
|
53
|
+
s.add_development_dependency(%q<guard-rspec>, ["~> 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
56
|
+
s.add_dependency(%q<yard>, ["~> 0"])
|
57
|
+
s.add_dependency(%q<rdoc>, ["~> 3"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 2"])
|
60
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
61
|
+
s.add_dependency(%q<semver>, ["~> 1"])
|
62
|
+
s.add_dependency(%q<guard-rspec>, ["~> 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2"])
|
66
|
+
s.add_dependency(%q<yard>, ["~> 0"])
|
67
|
+
s.add_dependency(%q<rdoc>, ["~> 3"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 2"])
|
70
|
+
s.add_dependency(%q<simplecov>, ["~> 0"])
|
71
|
+
s.add_dependency(%q<semver>, ["~> 1"])
|
72
|
+
s.add_dependency(%q<guard-rspec>, ["~> 0"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/lib/k-tree.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'k-tree/k-tree'
|
@@ -0,0 +1,94 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
= K-Tree -- a generalization of Quadtrees and Octrees
|
3
|
+
|
4
|
+
=end
|
5
|
+
|
6
|
+
require 'matrix'
|
7
|
+
|
8
|
+
module KTree
|
9
|
+
class KTreeException < Exception
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create(vupper = Vector[1.0, 1.0], vlower = Vector[-1.0, -1.0], depth: 5, &block)
|
13
|
+
KTree.new(vupper , vlower, depth, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
class KTree
|
17
|
+
include Enumerable
|
18
|
+
|
19
|
+
attr_reader :tuple, :depth
|
20
|
+
attr_accessor :root
|
21
|
+
|
22
|
+
# A node containing other nodes, 2^tuple
|
23
|
+
class Node
|
24
|
+
include Enumerable
|
25
|
+
|
26
|
+
# Coordinates of this node
|
27
|
+
attr_reader :center, :upper, :lower, :tuple, :depth
|
28
|
+
|
29
|
+
# Reference object for this node
|
30
|
+
attr_accessor :refob
|
31
|
+
|
32
|
+
def initialize(vupper, vlower, depth)
|
33
|
+
@upper = vupper
|
34
|
+
@lower = vlower
|
35
|
+
@depth = depth
|
36
|
+
@center = (vupper + vlower) / 2.0
|
37
|
+
@tuple = vupper.size
|
38
|
+
end
|
39
|
+
|
40
|
+
def children; @children ||= []; end
|
41
|
+
|
42
|
+
# iterate through all the upper, lower vectors
|
43
|
+
# of the possible children
|
44
|
+
def ntants
|
45
|
+
d = @upper - @center
|
46
|
+
(0...(2**@tuple)).map do |bits|
|
47
|
+
k = [Vector[*(0...@tuple).map{|i| (bits & (1 << 1)) == 0 ? @center[i]+d[i] : @center[i]-d[i]}], @center]
|
48
|
+
yield *k if block_given?
|
49
|
+
k
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# recursive function to create child nodes.
|
54
|
+
def create_children(&block)
|
55
|
+
if block.(self, cv = ntants)
|
56
|
+
unless @depth == 0
|
57
|
+
@children = cv.map{|vupper, vlower| Node.new(vupper, vlower, @depth - 1)}
|
58
|
+
@children.each{|child| child.create_children &block}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def each(&block)
|
64
|
+
block.(self)
|
65
|
+
children.each{|child| child.each &block }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def initialize(vupper , vlower, depth, &block)
|
70
|
+
@tuple = vupper.size
|
71
|
+
@depth = depth
|
72
|
+
@root = nil
|
73
|
+
raise KTreeException.new('tuple mismatch') unless vlower.size == vupper.size
|
74
|
+
create_tree(vupper, vlower, &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
# The block is passed node itself as parent and the vector midpoints of
|
78
|
+
# its children to be.
|
79
|
+
#
|
80
|
+
# The block sets is own refob, and returns either true, in which case
|
81
|
+
# all the children are created, or it returns false, in which case none
|
82
|
+
# of the children will be created, in effect, marking itself as a leaf
|
83
|
+
# node.
|
84
|
+
def create_tree(vupper, vlower, &block)
|
85
|
+
@root = Node.new(vupper, vlower, @depth)
|
86
|
+
@root.create_children &block
|
87
|
+
end
|
88
|
+
|
89
|
+
# Iterate through all nodes
|
90
|
+
def each(&block)
|
91
|
+
root.each(&block)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/spec/k-tree_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
describe KTree do
|
5
|
+
include KTree
|
6
|
+
|
7
|
+
let(:ktree) do
|
8
|
+
KTree.create(depth: 6) do |node, vchildren|
|
9
|
+
node.refob = rand(4)
|
10
|
+
node.refob != 0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "created a tree" do
|
15
|
+
expect(ktree).to_not be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has nodes" do
|
19
|
+
expect(ktree.root).to_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "upper and lower coords are never equal" do
|
23
|
+
ktree.each do |node|
|
24
|
+
expect(node.upper).to_not eq node.lower
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "refob should be set to something" do
|
29
|
+
ktree.each do |node|
|
30
|
+
expect(node.refob).to_not be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
require 'k-tree'
|
22
|
+
|
23
|
+
# Requires supporting files with custom matchers and macros, etc,
|
24
|
+
# in ./support/ and its subdirectories.
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: k-tree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fred Mitchell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: semver
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: "\n This is a data structure to represent and manage k-trees,\n primarily
|
126
|
+
created for use in RubyNEAT, but may see other possible applications.\n The goal
|
127
|
+
here is to be roebust in the creation of your k-tree, to allow\n you to prune during
|
128
|
+
creation, since, especially for higher-dimensional trees,\n the number of leaf
|
129
|
+
node can become very large.\n\n So a parent will have children nodes created down
|
130
|
+
to the desired resolution,\n and immediately after the creation of the children,
|
131
|
+
will check to see if there's\n enough variance among the children to keep them.
|
132
|
+
If not, they are pruned immediately.\n "
|
133
|
+
email: lordalveric@yahoo.com
|
134
|
+
executables: []
|
135
|
+
extensions: []
|
136
|
+
extra_rdoc_files:
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.rdoc
|
139
|
+
files:
|
140
|
+
- ".document"
|
141
|
+
- ".rspec"
|
142
|
+
- ".semver"
|
143
|
+
- Gemfile
|
144
|
+
- Gemfile.lock
|
145
|
+
- LICENSE.txt
|
146
|
+
- README.rdoc
|
147
|
+
- Rakefile
|
148
|
+
- k-tree.gemspec
|
149
|
+
- lib/k-tree.rb
|
150
|
+
- lib/k-tree/k-tree.rb
|
151
|
+
- spec/k-tree_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
homepage: http://github.com/flajann2/k-tree
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '2.0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.2.2
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: K-Tree is a generalization of quadtrees and octrees.
|
177
|
+
test_files: []
|