rambling-trie 0.5.1 → 0.5.2
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.
- data/.rspec +1 -1
- data/Guardfile +0 -11
- data/Rakefile +1 -3
- data/lib/rambling/trie/branches.rb +3 -3
- data/lib/rambling/trie/compressor.rb +9 -12
- data/lib/rambling/trie/inspector.rb +1 -1
- data/lib/rambling/trie/node.rb +17 -8
- data/lib/rambling/trie/root.rb +1 -1
- data/lib/rambling/trie/version.rb +1 -1
- data/rambling-trie.gemspec +3 -3
- data/reports/performance +28 -0
- data/spec/spec_helper.rb +6 -0
- metadata +9 -7
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
-c
|
1
|
+
-c -f d
|
data/Guardfile
CHANGED
@@ -5,16 +5,5 @@ guard 'rspec', all_on_start: true, all_after_pass: false do
|
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
7
|
watch('spec/spec_helper.rb') { "spec" }
|
8
|
-
|
9
|
-
# Rails example
|
10
|
-
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
-
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
-
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
-
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
-
watch('config/routes.rb') { "spec/routing" }
|
15
|
-
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
-
|
17
|
-
# Capybara request specs
|
18
|
-
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
8
|
end
|
20
9
|
|
data/Rakefile
CHANGED
@@ -31,7 +31,7 @@ module Rambling
|
|
31
31
|
protected
|
32
32
|
|
33
33
|
def branch_when_uncompressed?(chars)
|
34
|
-
chars.empty?
|
34
|
+
chars.empty? || fulfills_uncompressed_condition?(:branch_when_uncompressed?, chars)
|
35
35
|
end
|
36
36
|
|
37
37
|
def branch_when_compressed?(chars)
|
@@ -58,11 +58,11 @@ module Rambling
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def word_when_uncompressed?(chars)
|
61
|
-
(chars.empty?
|
61
|
+
(chars.empty? && terminal?) || fulfills_uncompressed_condition?(:word_when_uncompressed?, chars)
|
62
62
|
end
|
63
63
|
|
64
64
|
def word_when_compressed?(chars)
|
65
|
-
return true if chars.empty?
|
65
|
+
return true if chars.empty? && terminal?
|
66
66
|
|
67
67
|
first_letter = ''
|
68
68
|
while not chars.empty?
|
@@ -5,13 +5,13 @@ module Rambling
|
|
5
5
|
# Flag for compressed tries.
|
6
6
|
# @return [Boolean] `true` for compressed tries, `false` otherwise.
|
7
7
|
def compressed?
|
8
|
-
parent
|
8
|
+
parent && parent.compressed?
|
9
9
|
end
|
10
10
|
|
11
11
|
# Compress the current node using redundant node elimination.
|
12
12
|
# @return [Root, Node] the compressed node.
|
13
13
|
def compress_tree!
|
14
|
-
if children.size == 1
|
14
|
+
if children.size == 1 && !terminal? && letter
|
15
15
|
merge_with! children.values.first
|
16
16
|
compress_tree!
|
17
17
|
end
|
@@ -24,23 +24,20 @@ module Rambling
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def merge_with!(child)
|
27
|
-
|
27
|
+
delete_old_key_on_parent!
|
28
|
+
redefine_self! child
|
28
29
|
|
29
|
-
|
30
|
-
redefine_self! new_letter, child
|
31
|
-
|
32
|
-
children.values.each { |node| node.parent = self }
|
30
|
+
children.each { |_, node| node.parent = self }
|
33
31
|
end
|
34
32
|
|
35
|
-
def
|
33
|
+
def delete_old_key_on_parent!
|
36
34
|
return if parent.nil?
|
37
35
|
|
38
|
-
parent.delete
|
39
|
-
parent[new_letter] = self
|
36
|
+
parent.delete letter
|
40
37
|
end
|
41
38
|
|
42
|
-
def redefine_self!(
|
43
|
-
self.letter =
|
39
|
+
def redefine_self!(merged_node)
|
40
|
+
self.letter = letter.to_s << merged_node.letter.to_s
|
44
41
|
self.children = merged_node.children
|
45
42
|
self.terminal = merged_node.terminal?
|
46
43
|
end
|
@@ -4,7 +4,7 @@ module Rambling
|
|
4
4
|
module Inspector
|
5
5
|
# @return [String] a string representation of the current node.
|
6
6
|
def inspect
|
7
|
-
"#<#{self.class.name} letter: #{letter.inspect
|
7
|
+
"#<#{self.class.name} letter: #{letter.inspect || 'nil'}, children: #{children.keys}>"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/lib/rambling/trie/node.rb
CHANGED
@@ -27,9 +27,8 @@ module Rambling
|
|
27
27
|
self.parent = parent
|
28
28
|
self.children = {}
|
29
29
|
|
30
|
-
unless word.nil?
|
31
|
-
letter = word.slice! 0
|
32
|
-
self.letter = letter.to_sym if letter
|
30
|
+
unless word.nil? || word.empty?
|
31
|
+
self.letter = word.slice! 0
|
33
32
|
self.terminal = word.empty?
|
34
33
|
self << word
|
35
34
|
end
|
@@ -45,17 +44,27 @@ module Rambling
|
|
45
44
|
# @return [String] the string representation of the current node.
|
46
45
|
# @raise [InvalidOperation] if node is not terminal or is root.
|
47
46
|
def as_word
|
48
|
-
raise InvalidOperation, 'Cannot represent branch as a word'
|
49
|
-
|
47
|
+
raise InvalidOperation, 'Cannot represent branch as a word' if letter && !terminal?
|
48
|
+
to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
# String representation of the current node.
|
52
|
+
# @return [String] the string representation of the current node.
|
53
|
+
def to_s
|
54
|
+
parent.to_s << letter.to_s
|
50
55
|
end
|
51
56
|
|
52
57
|
protected
|
53
58
|
|
54
|
-
attr_writer :
|
59
|
+
attr_writer :children
|
55
60
|
attr_accessor :terminal
|
56
61
|
|
57
|
-
def
|
58
|
-
|
62
|
+
def letter=(letter)
|
63
|
+
return unless letter
|
64
|
+
|
65
|
+
letter = letter.to_sym
|
66
|
+
@letter = letter
|
67
|
+
parent[letter] = self if parent
|
59
68
|
end
|
60
69
|
end
|
61
70
|
end
|
data/lib/rambling/trie/root.rb
CHANGED
@@ -13,7 +13,7 @@ module Rambling
|
|
13
13
|
# Compresses the existing tree using redundant node elimination. Flags the trie as compressed.
|
14
14
|
# @return [Root] self
|
15
15
|
def compress!
|
16
|
-
self.compressed = (compressed?
|
16
|
+
self.compressed = (compressed? || !!compress_tree!)
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
data/rambling-trie.gemspec
CHANGED
@@ -3,11 +3,11 @@ $:.push File.expand_path('../lib', __FILE__)
|
|
3
3
|
require 'rambling/trie/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
|
-
gem.authors = ['
|
7
|
-
gem.email = ['
|
6
|
+
gem.authors = ['Edgar Gonzalez', 'Lilibeth De La Cruz']
|
7
|
+
gem.email = ['edggonzalezg@gmail.com', 'lilibethdlc@gmail.com']
|
8
8
|
gem.description = 'The Rambling Trie is a custom implementation of the Trie data structure with Ruby, which includes compression abilities and is designed to be very fast to traverse.'
|
9
9
|
gem.summary = 'A custom implementation of the trie data structure.'
|
10
|
-
gem.homepage = 'http://github.com/
|
10
|
+
gem.homepage = 'http://github.com/gonzedge/rambling-trie'
|
11
11
|
gem.date = Time.now.strftime '%Y-%m-%d'
|
12
12
|
|
13
13
|
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename f }
|
data/reports/performance
CHANGED
@@ -271,3 +271,31 @@ help - true 6.340000 0.010000 6.350000 ( 6.348615)
|
|
271
271
|
beautiful - true 7.920000 0.000000 7.920000 ( 7.920980)
|
272
272
|
impressionism - true 10.940000 0.020000 10.960000 ( 10.953487)
|
273
273
|
anthropological - true 10.620000 0.000000 10.620000 ( 10.623297)
|
274
|
+
|
275
|
+
Report for rambling-trie version 0.5.1
|
276
|
+
==> Uncompressed
|
277
|
+
`word?`:
|
278
|
+
hi - true 1.420000 0.000000 1.420000 ( 1.415907)
|
279
|
+
help - true 2.010000 0.010000 2.020000 ( 2.017104)
|
280
|
+
beautiful - true 3.450000 0.000000 3.450000 ( 3.442239)
|
281
|
+
impressionism - true 4.210000 0.000000 4.210000 ( 4.213081)
|
282
|
+
anthropological - true 4.680000 0.000000 4.680000 ( 4.681236)
|
283
|
+
`branch?`:
|
284
|
+
hi - true 1.420000 0.000000 1.420000 ( 1.421655)
|
285
|
+
help - true 2.200000 0.000000 2.200000 ( 2.203647)
|
286
|
+
beautiful - true 3.360000 0.000000 3.360000 ( 3.356781)
|
287
|
+
impressionism - true 4.170000 0.000000 4.170000 ( 4.170568)
|
288
|
+
anthropological - true 4.590000 0.000000 4.590000 ( 4.590748)
|
289
|
+
==> Compressed
|
290
|
+
`word?`:
|
291
|
+
hi - true 1.280000 0.000000 1.280000 ( 1.283929)
|
292
|
+
help - true 1.960000 0.000000 1.960000 ( 1.961445)
|
293
|
+
beautiful - true 3.110000 0.010000 3.120000 ( 3.106836)
|
294
|
+
impressionism - true 3.970000 0.000000 3.970000 ( 3.972552)
|
295
|
+
anthropological - true 4.380000 0.000000 4.380000 ( 4.379821)
|
296
|
+
`branch?`:
|
297
|
+
hi - true 3.170000 0.000000 3.170000 ( 3.175628)
|
298
|
+
help - true 6.140000 0.000000 6.140000 ( 6.136943)
|
299
|
+
beautiful - true 7.960000 0.000000 7.960000 ( 7.966746)
|
300
|
+
impressionism - true 10.820000 0.010000 10.830000 ( 10.820741)
|
301
|
+
anthropological - true 10.600000 0.000000 10.600000 ( 10.600866)
|
data/spec/spec_helper.rb
CHANGED
@@ -3,9 +3,15 @@ SimpleCov.start do
|
|
3
3
|
add_filter '/spec/'
|
4
4
|
end
|
5
5
|
|
6
|
+
require 'rspec'
|
6
7
|
require 'rambling-trie'
|
7
8
|
::SPEC_ROOT = File.dirname(__FILE__)
|
8
9
|
|
9
10
|
RSpec.configure do |config|
|
10
11
|
config.order = :random
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
|
14
|
+
config.expect_with :rspec do |c|
|
15
|
+
c.syntax = :expect
|
16
|
+
end
|
11
17
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rambling-trie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Edgar Gonzalez
|
9
|
+
- Lilibeth De La Cruz
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rspec
|
@@ -95,7 +96,8 @@ description: The Rambling Trie is a custom implementation of the Trie data struc
|
|
95
96
|
with Ruby, which includes compression abilities and is designed to be very fast
|
96
97
|
to traverse.
|
97
98
|
email:
|
98
|
-
-
|
99
|
+
- edggonzalezg@gmail.com
|
100
|
+
- lilibethdlc@gmail.com
|
99
101
|
executables: []
|
100
102
|
extensions: []
|
101
103
|
extra_rdoc_files: []
|
@@ -136,7 +138,7 @@ files:
|
|
136
138
|
- spec/lib/rambling/trie/root_spec.rb
|
137
139
|
- spec/lib/rambling/trie_spec.rb
|
138
140
|
- spec/spec_helper.rb
|
139
|
-
homepage: http://github.com/
|
141
|
+
homepage: http://github.com/gonzedge/rambling-trie
|
140
142
|
licenses: []
|
141
143
|
post_install_message:
|
142
144
|
rdoc_options: []
|
@@ -150,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
152
|
version: '0'
|
151
153
|
segments:
|
152
154
|
- 0
|
153
|
-
hash:
|
155
|
+
hash: 4017458515202388954
|
154
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
157
|
none: false
|
156
158
|
requirements:
|
@@ -159,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
161
|
version: '0'
|
160
162
|
segments:
|
161
163
|
- 0
|
162
|
-
hash:
|
164
|
+
hash: 4017458515202388954
|
163
165
|
requirements: []
|
164
166
|
rubyforge_project:
|
165
167
|
rubygems_version: 1.8.24
|