btree 0.0.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +41 -0
- data/README.md +2 -2
- data/Rakefile +2 -1
- data/lib/btree/node.rb +29 -5
- data/lib/btree/tree.rb +0 -2
- data/lib/insert_alot.rb +7 -0
- data/test/test_btree.rb +14 -2
- data/version.txt +1 -1
- metadata +42 -65
- data/.bnsignore +0 -18
- data/lib/btree/.node.rb.swp +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64a14900f4f059a6341312729643c101a88d19ea
|
4
|
+
data.tar.gz: da8ab66ed5bdf738658f2ef7ecb1421c9d58d1dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a1929ec3cb16b36af5ef5cbc1546bf59652f4aeddf6765b9ff70c7ea502c77827e29fb41ce7b556d7bb93c3cf6f293b46ce1ae06dcd79551cfe4b8e5d74924c
|
7
|
+
data.tar.gz: 26fc63048a49802026ba22661f025fc904d295ff0198c277dfd410650bbf539efb2477203e778d13e3328af2ed0247d6aeee1083d39bfaa5d88d545e5eb4d7f3
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
source "https://rubygems.org"
|
3
|
+
#repo_name "seifertd/Ruby-BTree"
|
4
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
5
|
+
|
6
|
+
# gem "rails"
|
7
|
+
|
8
|
+
# Added at 2017-11-09 08:39:45 -0800 by doug:
|
9
|
+
gem "rake", "~> 12.2", :group => [:development, :test]
|
10
|
+
|
11
|
+
# Added at 2017-11-09 08:40:02 -0800 by doug:
|
12
|
+
gem "bones", "~> 3.8", :group => [:development, :test]
|
13
|
+
|
14
|
+
# Added at 2017-11-09 08:40:12 -0800 by doug:
|
15
|
+
gem "shoulda", "~> 3.5", :group => [:development, :test]
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (5.1.4)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (~> 0.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
tzinfo (~> 1.1)
|
9
|
+
bones (3.8.4)
|
10
|
+
little-plugger (~> 1.1)
|
11
|
+
loquacious (~> 1.9)
|
12
|
+
rake (~> 12.0)
|
13
|
+
rdoc (~> 5.0)
|
14
|
+
concurrent-ruby (1.0.5)
|
15
|
+
i18n (0.9.1)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
little-plugger (1.1.4)
|
18
|
+
loquacious (1.9.1)
|
19
|
+
minitest (5.10.3)
|
20
|
+
rake (12.2.1)
|
21
|
+
rdoc (5.1.0)
|
22
|
+
shoulda (3.5.0)
|
23
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
24
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
25
|
+
shoulda-context (1.2.2)
|
26
|
+
shoulda-matchers (2.8.0)
|
27
|
+
activesupport (>= 3.0.0)
|
28
|
+
thread_safe (0.3.6)
|
29
|
+
tzinfo (1.2.4)
|
30
|
+
thread_safe (~> 0.1)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bones (~> 3.8)
|
37
|
+
rake (~> 12.2)
|
38
|
+
shoulda (~> 3.5)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.15.3
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -12,7 +12,8 @@ Bones {
|
|
12
12
|
name 'btree'
|
13
13
|
authors 'Douglas A. Seifert'
|
14
14
|
email 'doug@dseifert.net'
|
15
|
-
url '
|
15
|
+
url 'https://github.com/seifertd/Ruby-BTree'
|
16
16
|
readme_file 'README.md'
|
17
|
+
exclude ['.bnsignore', '.gitignore', '.ruby-gemset', '.ruby-version', '.travis.yml', 'vendor', '.git']
|
17
18
|
}
|
18
19
|
|
data/lib/btree/node.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
class Btree::Node
|
2
|
-
attr_accessor :leaf
|
3
2
|
def initialize(degree)
|
4
3
|
@degree = degree
|
5
4
|
@keys = []
|
6
5
|
@children = []
|
7
|
-
@leaf = true
|
8
6
|
end
|
9
7
|
|
10
8
|
def dump(level = 0)
|
11
9
|
@keys.each_with_index do |key, idx|
|
10
|
+
puts "LEVEL: #{level} => #{key.first}: full? #{full?} leaf? #{leaf?} children: #{values.inspect}"
|
12
11
|
if @children[idx]
|
13
12
|
@children[idx].dump(level + 1)
|
14
13
|
end
|
15
|
-
puts "#{level}: #{key.first}: full? #{full?} leaf? #{leaf?}"
|
16
14
|
end
|
17
15
|
(@children[@keys.size..-1] || []).each do |c|
|
18
16
|
c.dump(level+1)
|
@@ -41,24 +39,51 @@ class Btree::Node
|
|
41
39
|
end
|
42
40
|
|
43
41
|
def leaf?
|
44
|
-
@
|
42
|
+
@children.length == 0
|
45
43
|
end
|
46
44
|
|
47
45
|
def size
|
48
46
|
@keys.size
|
49
47
|
end
|
50
48
|
|
49
|
+
def values_of(range)
|
50
|
+
|
51
|
+
result = Array.new
|
52
|
+
|
53
|
+
i = 1
|
54
|
+
while i <= size && range.end >= @keys[i-1].first
|
55
|
+
if range.cover? @keys[i-1].first
|
56
|
+
result << @keys[i-1].last
|
57
|
+
child = @children[i-1].values_of(range) unless leaf?
|
58
|
+
result += child if child
|
59
|
+
end
|
60
|
+
i += 1
|
61
|
+
end
|
62
|
+
|
63
|
+
result
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
51
68
|
def value_of(key)
|
69
|
+
|
70
|
+
return values_of(key) if key.kind_of? Range
|
71
|
+
|
52
72
|
i = 1
|
53
73
|
while i <= size && key > @keys[i-1].first
|
54
74
|
i += 1
|
55
75
|
end
|
56
76
|
|
77
|
+
#puts "Getting value of key #{key}, i = #{i}, keys = #{@keys.inspect}, leaf? #{leaf?}, numchildren: #{@children.size}"
|
78
|
+
|
57
79
|
if i <= size && key == @keys[i-1].first
|
80
|
+
#puts "Found key: #{key.inspect}"
|
58
81
|
return @keys[i-1].last
|
59
82
|
elsif leaf?
|
83
|
+
#puts "We are a leaf, no more children, so val is nil"
|
60
84
|
return nil
|
61
85
|
else
|
86
|
+
#puts "Looking into child #{i}"
|
62
87
|
return @children[i-1].value_of(key)
|
63
88
|
end
|
64
89
|
end
|
@@ -94,7 +119,6 @@ class Btree::Node
|
|
94
119
|
splitee = @children[child_idx]
|
95
120
|
y = Btree::Node.new(@degree)
|
96
121
|
z = Btree::Node.new(@degree)
|
97
|
-
z.leaf = splitee.leaf
|
98
122
|
(@degree-1).times do |j|
|
99
123
|
z._keys[j] = splitee._keys[j+@degree]
|
100
124
|
y._keys[j] = splitee._keys[j]
|
data/lib/btree/tree.rb
CHANGED
@@ -6,7 +6,6 @@ class Btree::Tree
|
|
6
6
|
def initialize(degree = 2)
|
7
7
|
@degree = degree
|
8
8
|
@root = Btree::Node.new(@degree)
|
9
|
-
@root.leaf = true
|
10
9
|
@size = 0
|
11
10
|
end
|
12
11
|
|
@@ -15,7 +14,6 @@ class Btree::Tree
|
|
15
14
|
node = @root
|
16
15
|
if node.full?
|
17
16
|
@root = Btree::Node.new(@degree)
|
18
|
-
@root.leaf = false
|
19
17
|
@root.add_child(node)
|
20
18
|
@root.split(@root.children.size - 1)
|
21
19
|
#puts "After split, root = #{@root.inspect}"
|
data/lib/insert_alot.rb
ADDED
data/test/test_btree.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'minitest/autorun'
|
2
2
|
require 'btree'
|
3
3
|
require 'shoulda'
|
4
4
|
|
5
|
-
class TestBtree < Test
|
5
|
+
class TestBtree < MiniTest::Test
|
6
6
|
def test_insert_notfull
|
7
7
|
t = Btree.create(5)
|
8
8
|
t.insert(5, "5")
|
@@ -26,6 +26,17 @@ class TestBtree < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def test_insert_a_lot
|
30
|
+
t = Btree.create(2)
|
31
|
+
45.times do |i|
|
32
|
+
t.insert i, i*i
|
33
|
+
end
|
34
|
+
assert_equal 45, t.size
|
35
|
+
45.times do |i|
|
36
|
+
assert_equal i*i, t.value_of(i)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
29
40
|
def test_value_of
|
30
41
|
t = Btree.create(5)
|
31
42
|
t.insert(1, "foo")
|
@@ -38,6 +49,7 @@ class TestBtree < Test::Unit::TestCase
|
|
38
49
|
assert_equal "foo", t.value_of(1)
|
39
50
|
assert_nil t.value_of(11)
|
40
51
|
assert_equal 4, t.size
|
52
|
+
assert_equal ["findme", "bar"], t.value_of(3..6)
|
41
53
|
end
|
42
54
|
|
43
55
|
def test_fill_root
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.0.0
|
metadata
CHANGED
@@ -1,96 +1,73 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: btree
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 0.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Douglas A. Seifert
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2017-11-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: bones
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
27
17
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 5
|
33
|
-
- 4
|
34
|
-
version: 3.5.4
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.8.4
|
35
20
|
type: :development
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.8.4
|
27
|
+
description: "Pure ruby implementation of a btree as described in Introduction to
|
28
|
+
Algorithms by \nCormen, Leiserson, Rivest and Stein, Chapter 18."
|
40
29
|
email: doug@dseifert.net
|
41
30
|
executables: []
|
42
|
-
|
43
31
|
extensions: []
|
44
|
-
|
45
|
-
extra_rdoc_files:
|
32
|
+
extra_rdoc_files:
|
46
33
|
- History.txt
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
- .bnsignore
|
34
|
+
files:
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
51
37
|
- History.txt
|
52
38
|
- README.md
|
53
39
|
- Rakefile
|
54
40
|
- lib/btree.rb
|
55
|
-
- lib/btree/.node.rb.swp
|
56
41
|
- lib/btree/node.rb
|
57
42
|
- lib/btree/tree.rb
|
43
|
+
- lib/insert_alot.rb
|
58
44
|
- test/test_btree.rb
|
59
45
|
- version.txt
|
60
|
-
|
61
|
-
homepage: http://www.dseifert.net/btree
|
46
|
+
homepage: https://github.com/seifertd/Ruby-BTree
|
62
47
|
licenses: []
|
63
|
-
|
48
|
+
metadata: {}
|
64
49
|
post_install_message:
|
65
|
-
rdoc_options:
|
66
|
-
- --main
|
50
|
+
rdoc_options:
|
51
|
+
- "--main"
|
67
52
|
- README.md
|
68
|
-
require_paths:
|
53
|
+
require_paths:
|
69
54
|
- lib
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
|
72
|
-
requirements:
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
73
57
|
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
version: "0"
|
79
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
|
-
requirements:
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
82
62
|
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
version: "0"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
88
65
|
requirements: []
|
89
|
-
|
90
66
|
rubyforge_project: btree
|
91
|
-
rubygems_version:
|
67
|
+
rubygems_version: 2.6.12
|
92
68
|
signing_key:
|
93
|
-
specification_version:
|
94
|
-
summary: Pure ruby implementation of a btree as described in Introduction to Algorithms
|
95
|
-
|
69
|
+
specification_version: 4
|
70
|
+
summary: Pure ruby implementation of a btree as described in Introduction to Algorithms
|
71
|
+
by Cormen, Leiserson, Rivest and Stein, Chapter 18.
|
72
|
+
test_files:
|
96
73
|
- test/test_btree.rb
|
data/.bnsignore
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# The list of files that should be ignored by Mr Bones.
|
2
|
-
# Lines that start with '#' are comments.
|
3
|
-
#
|
4
|
-
# A .gitignore file can be used instead by setting it as the ignore
|
5
|
-
# file in your Rakefile:
|
6
|
-
#
|
7
|
-
# Bones {
|
8
|
-
# ignore_file '.gitignore'
|
9
|
-
# }
|
10
|
-
#
|
11
|
-
# For a project with a C extension, the following would be a good set of
|
12
|
-
# exclude patterns (uncomment them if you want to use them):
|
13
|
-
# *.[oa]
|
14
|
-
# *~
|
15
|
-
announcement.txt
|
16
|
-
coverage
|
17
|
-
doc
|
18
|
-
pkg
|
data/lib/btree/.node.rb.swp
DELETED
Binary file
|