rambling-trie 1.0.3 → 2.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 +5 -5
- data/Gemfile +6 -4
- data/Guardfile +3 -1
- data/README.md +4 -4
- data/Rakefile +4 -0
- data/lib/rambling-trie.rb +2 -0
- data/lib/rambling/trie.rb +25 -9
- data/lib/rambling/trie/comparable.rb +4 -1
- data/lib/rambling/trie/compressible.rb +6 -4
- data/lib/rambling/trie/compressor.rb +12 -10
- data/lib/rambling/trie/configuration.rb +3 -1
- data/lib/rambling/trie/configuration/properties.rb +15 -8
- data/lib/rambling/trie/configuration/provider_collection.rb +4 -1
- data/lib/rambling/trie/container.rb +7 -40
- data/lib/rambling/trie/enumerable.rb +2 -0
- data/lib/rambling/trie/inspectable.rb +2 -0
- data/lib/rambling/trie/invalid_operation.rb +3 -1
- data/lib/rambling/trie/nodes.rb +3 -1
- data/lib/rambling/trie/nodes/compressed.rb +53 -70
- data/lib/rambling/trie/nodes/missing.rb +2 -0
- data/lib/rambling/trie/nodes/node.rb +38 -6
- data/lib/rambling/trie/nodes/raw.rb +19 -26
- data/lib/rambling/trie/readers.rb +3 -1
- data/lib/rambling/trie/readers/plain_text.rb +2 -0
- data/lib/rambling/trie/serializers.rb +3 -1
- data/lib/rambling/trie/serializers/file.rb +2 -0
- data/lib/rambling/trie/serializers/marshal.rb +12 -2
- data/lib/rambling/trie/serializers/yaml.rb +18 -2
- data/lib/rambling/trie/serializers/zip.rb +6 -0
- data/lib/rambling/trie/stringifyable.rb +7 -1
- data/lib/rambling/trie/version.rb +3 -1
- data/rambling-trie.gemspec +21 -10
- data/spec/integration/rambling/trie_spec.rb +8 -4
- data/spec/lib/rambling/trie/comparable_spec.rb +2 -0
- data/spec/lib/rambling/trie/compressor_spec.rb +35 -33
- data/spec/lib/rambling/trie/configuration/properties_spec.rb +17 -9
- data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +10 -14
- data/spec/lib/rambling/trie/container_spec.rb +28 -53
- data/spec/lib/rambling/trie/enumerable_spec.rb +2 -0
- data/spec/lib/rambling/trie/inspectable_spec.rb +32 -7
- data/spec/lib/rambling/trie/nodes/compressed_spec.rb +2 -0
- data/spec/lib/rambling/trie/nodes/node_spec.rb +2 -0
- data/spec/lib/rambling/trie/nodes/raw_spec.rb +2 -0
- data/spec/lib/rambling/trie/readers/plain_text_spec.rb +3 -1
- data/spec/lib/rambling/trie/serializers/file_spec.rb +2 -0
- data/spec/lib/rambling/trie/serializers/marshal_spec.rb +2 -0
- data/spec/lib/rambling/trie/serializers/yaml_spec.rb +2 -0
- data/spec/lib/rambling/trie/serializers/zip_spec.rb +6 -4
- data/spec/lib/rambling/trie/stringifyable_spec.rb +7 -3
- data/spec/lib/rambling/trie_spec.rb +16 -9
- data/spec/spec_helper.rb +10 -7
- data/spec/support/config.rb +6 -0
- data/spec/support/helpers/add_word.rb +2 -0
- data/spec/support/helpers/one_line_heredoc.rb +11 -0
- data/spec/support/shared_examples/a_compressible_trie.rb +7 -3
- data/spec/support/shared_examples/a_serializable_trie.rb +2 -0
- data/spec/support/shared_examples/a_serializer.rb +2 -0
- data/spec/support/shared_examples/a_trie_data_structure.rb +2 -0
- data/spec/support/shared_examples/a_trie_node.rb +15 -5
- data/spec/support/shared_examples/a_trie_node_implementation.rb +10 -6
- metadata +17 -15
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'simplecov'
|
2
4
|
require 'coveralls'
|
3
5
|
|
@@ -5,7 +7,7 @@ Coveralls.wear!
|
|
5
7
|
|
6
8
|
SimpleCov.formatters = [
|
7
9
|
SimpleCov::Formatter::HTMLFormatter,
|
8
|
-
Coveralls::SimpleCov::Formatter
|
10
|
+
Coveralls::SimpleCov::Formatter,
|
9
11
|
]
|
10
12
|
|
11
13
|
SimpleCov.start do
|
@@ -26,9 +28,10 @@ RSpec.configure do |config|
|
|
26
28
|
end
|
27
29
|
|
28
30
|
require 'support/config'
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
require 'support
|
31
|
+
|
32
|
+
%w(
|
33
|
+
a_compressible_trie a_serializable_trie a_serializer a_trie_data_structure
|
34
|
+
a_trie_node a_trie_node_implementation
|
35
|
+
).each do |name|
|
36
|
+
require File.join('support', 'shared_examples', name)
|
37
|
+
end
|
data/spec/support/config.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'helpers/add_word'
|
4
|
+
require_relative 'helpers/one_line_heredoc'
|
2
5
|
|
3
6
|
RSpec.configure do |c|
|
4
7
|
c.before do
|
@@ -6,4 +9,7 @@ RSpec.configure do |c|
|
|
6
9
|
end
|
7
10
|
|
8
11
|
c.include Support::Helpers::AddWord
|
12
|
+
c.include Support::Helpers::OneLineHeredoc
|
13
|
+
|
14
|
+
RSpec::Matchers.define_negated_matcher :not_change, :change
|
9
15
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for 'a compressible trie' do
|
2
4
|
context 'and the trie is not compressed' do
|
3
5
|
it_behaves_like 'a trie data structure'
|
@@ -16,7 +18,8 @@ shared_examples_for 'a compressible trie' do
|
|
16
18
|
|
17
19
|
context 'and the trie is compressed' do
|
18
20
|
let!(:original_root) { trie.root }
|
19
|
-
let!(:
|
21
|
+
let!(:original_keys) { original_root.children_tree.keys }
|
22
|
+
let!(:original_values) { original_root.children_tree.values }
|
20
23
|
|
21
24
|
before do
|
22
25
|
trie.compress!
|
@@ -29,8 +32,9 @@ shared_examples_for 'a compressible trie' do
|
|
29
32
|
end
|
30
33
|
|
31
34
|
it 'leaves the original root intact' do
|
32
|
-
expect(original_root.children_tree.keys).to eq
|
33
|
-
expect(trie.children_tree.keys).
|
35
|
+
expect(original_root.children_tree.keys).to eq original_keys
|
36
|
+
expect(trie.children_tree.keys).to eq original_keys
|
37
|
+
expect(trie.children_tree.values).not_to eq original_values
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for 'a trie node' do
|
2
4
|
let(:node_class) { node.class }
|
3
5
|
|
@@ -73,12 +75,13 @@ shared_examples_for 'a trie node' do
|
|
73
75
|
|
74
76
|
describe 'delegates and aliases' do
|
75
77
|
let(:children_tree) do
|
76
|
-
double
|
78
|
+
double(
|
79
|
+
:children_tree,
|
77
80
|
:[] => 'value',
|
78
81
|
:[]= => nil,
|
79
|
-
|
82
|
+
key?: false,
|
80
83
|
delete: true,
|
81
|
-
|
84
|
+
)
|
82
85
|
end
|
83
86
|
|
84
87
|
before do
|
@@ -95,8 +98,10 @@ shared_examples_for 'a trie node' do
|
|
95
98
|
expect(children_tree).to have_received(:[]=).with(:key, 'value')
|
96
99
|
end
|
97
100
|
|
98
|
-
it 'delegates `#
|
99
|
-
allow(children_tree).to receive(:
|
101
|
+
it 'delegates `#key?` to its children tree' do
|
102
|
+
allow(children_tree).to receive(:key?)
|
103
|
+
.with(:present_key)
|
104
|
+
.and_return true
|
100
105
|
|
101
106
|
expect(node).to have_key(:present_key)
|
102
107
|
expect(node).not_to have_key(:absent_key)
|
@@ -113,5 +118,10 @@ shared_examples_for 'a trie node' do
|
|
113
118
|
|
114
119
|
expect(node.children).to eq children
|
115
120
|
end
|
121
|
+
|
122
|
+
it 'aliases `#has_key?` to `#key?`' do
|
123
|
+
node.has_key? :nope
|
124
|
+
expect(children_tree).to have_received(:key?).with :nope
|
125
|
+
end
|
116
126
|
end
|
117
127
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for 'a trie node implementation' do
|
2
4
|
it_behaves_like 'a trie node'
|
3
5
|
|
@@ -61,18 +63,18 @@ shared_examples_for 'a trie node implementation' do
|
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'returns true' do
|
64
|
-
expect(node.word? %w(a b c)).to be true
|
66
|
+
expect(node.word? %w(a b c).map(&:dup)).to be true
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
68
|
-
context 'when the node
|
70
|
+
context 'when the node subtree does not match all the characters' do
|
69
71
|
before do
|
70
72
|
add_word_to_tree 'abc'
|
71
73
|
end
|
72
74
|
|
73
75
|
it 'returns false' do
|
74
|
-
expect(node.word? %w(a)).to be false
|
75
|
-
expect(node.word? %w(a b)).to be false
|
76
|
+
expect(node.word? %w(a).map(&:dup)).to be false
|
77
|
+
expect(node.word? %w(a b).map(&:dup)).to be false
|
76
78
|
end
|
77
79
|
end
|
78
80
|
end
|
@@ -87,12 +89,12 @@ shared_examples_for 'a trie node implementation' do
|
|
87
89
|
|
88
90
|
context 'when the chars array is not empty' do
|
89
91
|
before do
|
90
|
-
|
92
|
+
add_words_to_tree %w(cba ccab)
|
91
93
|
end
|
92
94
|
|
93
95
|
context 'when the chars are found' do
|
94
96
|
it 'returns the found child' do
|
95
|
-
expect(node.scan %w(c)).to match_array %w(cba)
|
97
|
+
expect(node.scan %w(c)).to match_array %w(cba ccab)
|
96
98
|
expect(node.scan %w(c b)).to match_array %w(cba)
|
97
99
|
expect(node.scan %w(c b a)).to match_array %w(cba)
|
98
100
|
end
|
@@ -103,6 +105,8 @@ shared_examples_for 'a trie node implementation' do
|
|
103
105
|
expect(node.scan %w(a)).to be_a Rambling::Trie::Nodes::Missing
|
104
106
|
expect(node.scan %w(a b)).to be_a Rambling::Trie::Nodes::Missing
|
105
107
|
expect(node.scan %w(a b c)).to be_a Rambling::Trie::Nodes::Missing
|
108
|
+
expect(node.scan %w(c a)).to be_a Rambling::Trie::Nodes::Missing
|
109
|
+
expect(node.scan %w(c c b)).to be_a Rambling::Trie::Nodes::Missing
|
106
110
|
expect(node.scan %w(c b a d)).to be_a Rambling::Trie::Nodes::Missing
|
107
111
|
end
|
108
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rambling-trie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar Gonzalez
|
@@ -9,52 +9,52 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: rake
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '3
|
20
|
+
version: '12.3'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '3
|
27
|
+
version: '12.3'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: rspec
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '3.7'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '3.7'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: yard
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.9.
|
48
|
+
version: 0.9.12
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.9.
|
56
|
-
description: The Rambling Trie is a Ruby implementation of the trie data structure,
|
57
|
-
which includes compression abilities and is designed to be very fast to traverse.
|
55
|
+
version: 0.9.12
|
56
|
+
description: 'The Rambling Trie is a Ruby implementation of the trie data structure,
|
57
|
+
which includes compression abilities and is designed to be very fast to traverse. '
|
58
58
|
email:
|
59
59
|
- edggonzalezg@gmail.com
|
60
60
|
- lilibethdlc@gmail.com
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- spec/spec_helper.rb
|
118
118
|
- spec/support/config.rb
|
119
119
|
- spec/support/helpers/add_word.rb
|
120
|
+
- spec/support/helpers/one_line_heredoc.rb
|
120
121
|
- spec/support/shared_examples/a_compressible_trie.rb
|
121
122
|
- spec/support/shared_examples/a_serializable_trie.rb
|
122
123
|
- spec/support/shared_examples/a_serializer.rb
|
@@ -134,9 +135,9 @@ require_paths:
|
|
134
135
|
- lib
|
135
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
137
|
requirements:
|
137
|
-
- - "
|
138
|
+
- - "~>"
|
138
139
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
140
|
+
version: '2.3'
|
140
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
142
|
requirements:
|
142
143
|
- - ">="
|
@@ -144,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
145
|
version: '0'
|
145
146
|
requirements: []
|
146
147
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.6
|
148
|
+
rubygems_version: 2.7.6
|
148
149
|
signing_key:
|
149
150
|
specification_version: 4
|
150
151
|
summary: A Ruby implementation of the trie data structure.
|
@@ -172,6 +173,7 @@ test_files:
|
|
172
173
|
- spec/spec_helper.rb
|
173
174
|
- spec/support/config.rb
|
174
175
|
- spec/support/helpers/add_word.rb
|
176
|
+
- spec/support/helpers/one_line_heredoc.rb
|
175
177
|
- spec/support/shared_examples/a_compressible_trie.rb
|
176
178
|
- spec/support/shared_examples/a_serializable_trie.rb
|
177
179
|
- spec/support/shared_examples/a_serializer.rb
|