rambling-trie 2.3.0 → 2.4.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 +4 -4
- data/Gemfile +6 -0
- data/LICENSE +1 -1
- data/README.md +68 -29
- data/lib/rambling/trie/comparable.rb +2 -3
- data/lib/rambling/trie/compressible.rb +3 -5
- data/lib/rambling/trie/compressor.rb +2 -12
- data/lib/rambling/trie/configuration/properties.rb +8 -14
- data/lib/rambling/trie/configuration/provider_collection.rb +19 -27
- data/lib/rambling/trie/container.rb +28 -42
- data/lib/rambling/trie/enumerable.rb +4 -2
- data/lib/rambling/trie/nodes/compressed.rb +4 -5
- data/lib/rambling/trie/nodes/missing.rb +1 -2
- data/lib/rambling/trie/nodes/node.rb +21 -34
- data/lib/rambling/trie/nodes/raw.rb +2 -2
- data/lib/rambling/trie/readers/plain_text.rb +10 -6
- data/lib/rambling/trie/readers/reader.rb +19 -0
- data/lib/rambling/trie/readers.rb +1 -1
- data/lib/rambling/trie/serializers/file.rb +1 -1
- data/lib/rambling/trie/serializers/marshal.rb +12 -20
- data/lib/rambling/trie/serializers/serializer.rb +27 -0
- data/lib/rambling/trie/serializers/yaml.rb +10 -16
- data/lib/rambling/trie/serializers/zip.rb +9 -5
- data/lib/rambling/trie/serializers.rb +1 -1
- data/lib/rambling/trie/stringifyable.rb +1 -1
- data/lib/rambling/trie/version.rb +1 -1
- data/lib/rambling/trie.rb +19 -22
- data/rambling-trie.gemspec +9 -5
- data/spec/integration/rambling/trie_spec.rb +49 -20
- data/spec/lib/rambling/trie/comparable_spec.rb +29 -39
- data/spec/lib/rambling/trie/compressor_spec.rb +17 -14
- data/spec/lib/rambling/trie/configuration/properties_spec.rb +25 -7
- data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +44 -16
- data/spec/lib/rambling/trie/container_spec.rb +202 -327
- data/spec/lib/rambling/trie/enumerable_spec.rb +18 -10
- data/spec/lib/rambling/trie/inspectable_spec.rb +9 -3
- data/spec/lib/rambling/trie/nodes/compressed_spec.rb +6 -0
- data/spec/lib/rambling/trie/nodes/node_spec.rb +1 -1
- data/spec/lib/rambling/trie/nodes/raw_spec.rb +32 -27
- data/spec/lib/rambling/trie/readers/plain_text_spec.rb +11 -1
- data/spec/lib/rambling/trie/readers/reader_spec.rb +14 -0
- data/spec/lib/rambling/trie/serializers/file_spec.rb +2 -4
- data/spec/lib/rambling/trie/serializers/marshal_spec.rb +2 -4
- data/spec/lib/rambling/trie/serializers/serializer_spec.rb +21 -0
- data/spec/lib/rambling/trie/serializers/yaml_spec.rb +2 -4
- data/spec/lib/rambling/trie/serializers/zip_spec.rb +24 -16
- data/spec/lib/rambling/trie/stringifyable_spec.rb +17 -13
- data/spec/lib/rambling/trie_spec.rb +107 -45
- data/spec/spec_helper.rb +16 -9
- data/spec/support/shared_examples/a_compressible_trie.rb +9 -3
- data/spec/support/shared_examples/a_container_partial_word.rb +17 -0
- data/spec/support/shared_examples/a_container_scan.rb +14 -0
- data/spec/support/shared_examples/a_container_word.rb +43 -0
- data/spec/support/shared_examples/a_container_words_within.rb +44 -0
- data/spec/support/shared_examples/a_serializable_trie.rb +5 -9
- data/spec/support/shared_examples/a_serializer.rb +37 -14
- data/spec/support/shared_examples/a_trie_data_structure.rb +24 -10
- data/spec/support/shared_examples/a_trie_node.rb +22 -14
- data/spec/support/shared_examples/a_trie_node_implementation.rb +40 -43
- metadata +25 -9
@@ -21,7 +21,8 @@ shared_examples_for 'a trie node' do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'with a letter and a parent' do
|
24
|
-
let(:parent) {
|
24
|
+
let(:parent) { node_class.new }
|
25
|
+
# noinspection RubyArgCount
|
25
26
|
let(:node_with_parent) { node_class.new :a, parent }
|
26
27
|
|
27
28
|
it 'does not have any letter' do
|
@@ -40,9 +41,7 @@ shared_examples_for 'a trie node' do
|
|
40
41
|
|
41
42
|
describe '#root?' do
|
42
43
|
context 'when the node has a parent' do
|
43
|
-
before
|
44
|
-
node.parent = node
|
45
|
-
end
|
44
|
+
before { node.parent = node }
|
46
45
|
|
47
46
|
it 'returns false' do
|
48
47
|
expect(node).not_to be_root
|
@@ -50,9 +49,7 @@ shared_examples_for 'a trie node' do
|
|
50
49
|
end
|
51
50
|
|
52
51
|
context 'when the node does not have a parent' do
|
53
|
-
before
|
54
|
-
node.parent = nil
|
55
|
-
end
|
52
|
+
before { node.parent = nil }
|
56
53
|
|
57
54
|
it 'returns true' do
|
58
55
|
expect(node).to be_root
|
@@ -61,12 +58,13 @@ shared_examples_for 'a trie node' do
|
|
61
58
|
end
|
62
59
|
|
63
60
|
describe '#terminal!' do
|
61
|
+
# rubocop:disable RSpec/MultipleExpectations
|
64
62
|
it 'forces the node to be terminal' do
|
65
63
|
expect(node).not_to be_terminal
|
66
64
|
node.terminal!
|
67
|
-
|
68
65
|
expect(node).to be_terminal
|
69
66
|
end
|
67
|
+
# rubocop:enable RSpec/MultipleExpectations
|
70
68
|
|
71
69
|
it 'returns the node' do
|
72
70
|
expect(node.terminal!).to eq node
|
@@ -74,8 +72,9 @@ shared_examples_for 'a trie node' do
|
|
74
72
|
end
|
75
73
|
|
76
74
|
describe 'delegates and aliases' do
|
77
|
-
let
|
78
|
-
|
75
|
+
let :children_tree do
|
76
|
+
instance_double(
|
77
|
+
'Hash',
|
79
78
|
:children_tree,
|
80
79
|
:[] => 'value',
|
81
80
|
:[]= => nil,
|
@@ -84,20 +83,21 @@ shared_examples_for 'a trie node' do
|
|
84
83
|
)
|
85
84
|
end
|
86
85
|
|
87
|
-
before
|
88
|
-
node.children_tree = children_tree
|
89
|
-
end
|
86
|
+
before { node.children_tree = children_tree }
|
90
87
|
|
88
|
+
# rubocop:disable RSpec/MultipleExpectations
|
91
89
|
it 'delegates `#[]` to its children tree' do
|
92
90
|
expect(node[:key]).to eq 'value'
|
93
91
|
expect(children_tree).to have_received(:[]).with :key
|
94
92
|
end
|
93
|
+
# rubocop:enable RSpec/MultipleExpectations
|
95
94
|
|
96
95
|
it 'delegates `#[]=` to its children tree' do
|
97
96
|
node[:key] = 'value'
|
98
97
|
expect(children_tree).to have_received(:[]=).with(:key, 'value')
|
99
98
|
end
|
100
99
|
|
100
|
+
# rubocop:disable RSpec/MultipleExpectations
|
101
101
|
it 'delegates `#key?` to its children tree' do
|
102
102
|
allow(children_tree).to receive(:key?)
|
103
103
|
.with(:present_key)
|
@@ -106,18 +106,26 @@ shared_examples_for 'a trie node' do
|
|
106
106
|
expect(node).to have_key(:present_key)
|
107
107
|
expect(node).not_to have_key(:absent_key)
|
108
108
|
end
|
109
|
+
# rubocop:enable RSpec/MultipleExpectations
|
109
110
|
|
111
|
+
# rubocop:disable RSpec/MultipleExpectations
|
110
112
|
it 'delegates `#delete` to its children tree' do
|
111
113
|
expect(node.delete :key).to be true
|
112
114
|
expect(children_tree).to have_received(:delete).with :key
|
113
115
|
end
|
116
|
+
# rubocop:enable RSpec/MultipleExpectations
|
114
117
|
|
118
|
+
# rubocop:disable RSpec/ExampleLength
|
115
119
|
it 'delegates `#children` to its children tree values' do
|
116
|
-
children = [
|
120
|
+
children = [
|
121
|
+
instance_double('Rambling::Trie::Nodes::Node', :child_one),
|
122
|
+
instance_double('Rambling::Trie::Nodes::Node', :child_two),
|
123
|
+
]
|
117
124
|
allow(children_tree).to receive(:values).and_return children
|
118
125
|
|
119
126
|
expect(node.children).to eq children
|
120
127
|
end
|
128
|
+
# rubocop:enable RSpec/ExampleLength
|
121
129
|
|
122
130
|
it 'aliases `#has_key?` to `#key?`' do
|
123
131
|
node.has_key? :nope
|
@@ -12,26 +12,22 @@ shared_examples_for 'a trie node implementation' do
|
|
12
12
|
|
13
13
|
context 'when the chars array is not empty' do
|
14
14
|
context 'when the node has a tree that matches the characters' do
|
15
|
-
before
|
16
|
-
add_word_to_tree 'abc'
|
17
|
-
end
|
15
|
+
before { add_word_to_tree 'abc' }
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
[%w(a), %w(a b), %w(a b c)].each do |letters|
|
18
|
+
it "returns true for '#{letters}'" do
|
19
|
+
expect(node.partial_word? letters).to be true
|
20
|
+
end
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
24
|
context 'when the node has a tree that does not match the characters' do
|
27
|
-
before
|
28
|
-
add_word_to_tree 'cba'
|
29
|
-
end
|
25
|
+
before { add_word_to_tree 'cba' }
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
[%w(a), %w(a b), %w(a b c)].each do |letters|
|
28
|
+
it "returns false for '#{letters}'" do
|
29
|
+
expect(node.partial_word? letters).to be false
|
30
|
+
end
|
35
31
|
end
|
36
32
|
end
|
37
33
|
end
|
@@ -40,9 +36,7 @@ shared_examples_for 'a trie node implementation' do
|
|
40
36
|
describe '#word?' do
|
41
37
|
context 'when the chars array is empty' do
|
42
38
|
context 'when the node is terminal' do
|
43
|
-
before
|
44
|
-
node.terminal!
|
45
|
-
end
|
39
|
+
before { node.terminal! }
|
46
40
|
|
47
41
|
it 'returns true' do
|
48
42
|
expect(node.word? []).to be true
|
@@ -58,9 +52,7 @@ shared_examples_for 'a trie node implementation' do
|
|
58
52
|
|
59
53
|
context 'when the chars array is not empty' do
|
60
54
|
context 'when the node has a tree that matches all the characters' do
|
61
|
-
before
|
62
|
-
add_word_to_tree 'abc'
|
63
|
-
end
|
55
|
+
before { add_word_to_tree 'abc' }
|
64
56
|
|
65
57
|
it 'returns true' do
|
66
58
|
expect(node.word? %w(a b c).map(&:dup)).to be true
|
@@ -68,13 +60,12 @@ shared_examples_for 'a trie node implementation' do
|
|
68
60
|
end
|
69
61
|
|
70
62
|
context 'when the node subtree does not match all the characters' do
|
71
|
-
before
|
72
|
-
add_word_to_tree 'abc'
|
73
|
-
end
|
63
|
+
before { add_word_to_tree 'abc' }
|
74
64
|
|
75
|
-
|
76
|
-
|
77
|
-
|
65
|
+
[%w(a), %w(a b)].each do |letters|
|
66
|
+
it "returns false for '#{letters}'" do
|
67
|
+
expect(node.word? letters.map(&:dup)).to be false
|
68
|
+
end
|
78
69
|
end
|
79
70
|
end
|
80
71
|
end
|
@@ -88,26 +79,34 @@ shared_examples_for 'a trie node implementation' do
|
|
88
79
|
end
|
89
80
|
|
90
81
|
context 'when the chars array is not empty' do
|
91
|
-
before
|
92
|
-
add_words_to_tree %w(cba ccab)
|
93
|
-
end
|
82
|
+
before { add_words_to_tree %w(cba ccab) }
|
94
83
|
|
95
84
|
context 'when the chars are found' do
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
85
|
+
[
|
86
|
+
[%w(c), %w(cba ccab)],
|
87
|
+
[%w(c b), %w(cba)],
|
88
|
+
[%w(c b a), %w(cba)],
|
89
|
+
].each do |test_params|
|
90
|
+
letters, expected = test_params
|
91
|
+
|
92
|
+
it "returns the corresponding children (#{letters} => #{expected})" do
|
93
|
+
expect(node.scan letters).to match_array expected
|
94
|
+
end
|
100
95
|
end
|
101
96
|
end
|
102
97
|
|
103
98
|
context 'when the chars are not found' do
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
99
|
+
[
|
100
|
+
%w(a),
|
101
|
+
%w(a b),
|
102
|
+
%w(a b c),
|
103
|
+
%w(c a),
|
104
|
+
%w(c c b),
|
105
|
+
%w(c b a d),
|
106
|
+
].each do |letters|
|
107
|
+
it "returns a Nodes::Missing for '#{letters}'" do
|
108
|
+
expect(node.scan letters).to be_a Rambling::Trie::Nodes::Missing
|
109
|
+
end
|
111
110
|
end
|
112
111
|
end
|
113
112
|
end
|
@@ -120,9 +119,7 @@ shared_examples_for 'a trie node implementation' do
|
|
120
119
|
end
|
121
120
|
|
122
121
|
context 'when the node is terminal' do
|
123
|
-
before
|
124
|
-
node.terminal!
|
125
|
-
end
|
122
|
+
before { node.terminal! }
|
126
123
|
|
127
124
|
it 'adds itself to the words' do
|
128
125
|
expect(node.match_prefix %w(g n i t e)).to include 'i'
|
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: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar Gonzalez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '13.
|
20
|
+
version: '13.1'
|
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: '13.
|
27
|
+
version: '13.1'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rspec
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.9.
|
48
|
+
version: 0.9.34
|
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.
|
55
|
+
version: 0.9.34
|
56
56
|
description: 'The Rambling Trie is a Ruby implementation of the trie data structure,
|
57
57
|
which includes compression abilities and is designed to be very fast to traverse. '
|
58
58
|
email:
|
@@ -86,9 +86,11 @@ files:
|
|
86
86
|
- lib/rambling/trie/nodes/raw.rb
|
87
87
|
- lib/rambling/trie/readers.rb
|
88
88
|
- lib/rambling/trie/readers/plain_text.rb
|
89
|
+
- lib/rambling/trie/readers/reader.rb
|
89
90
|
- lib/rambling/trie/serializers.rb
|
90
91
|
- lib/rambling/trie/serializers/file.rb
|
91
92
|
- lib/rambling/trie/serializers/marshal.rb
|
93
|
+
- lib/rambling/trie/serializers/serializer.rb
|
92
94
|
- lib/rambling/trie/serializers/yaml.rb
|
93
95
|
- lib/rambling/trie/serializers/zip.rb
|
94
96
|
- lib/rambling/trie/stringifyable.rb
|
@@ -108,8 +110,10 @@ files:
|
|
108
110
|
- spec/lib/rambling/trie/nodes/node_spec.rb
|
109
111
|
- spec/lib/rambling/trie/nodes/raw_spec.rb
|
110
112
|
- spec/lib/rambling/trie/readers/plain_text_spec.rb
|
113
|
+
- spec/lib/rambling/trie/readers/reader_spec.rb
|
111
114
|
- spec/lib/rambling/trie/serializers/file_spec.rb
|
112
115
|
- spec/lib/rambling/trie/serializers/marshal_spec.rb
|
116
|
+
- spec/lib/rambling/trie/serializers/serializer_spec.rb
|
113
117
|
- spec/lib/rambling/trie/serializers/yaml_spec.rb
|
114
118
|
- spec/lib/rambling/trie/serializers/zip_spec.rb
|
115
119
|
- spec/lib/rambling/trie/stringifyable_spec.rb
|
@@ -119,16 +123,22 @@ files:
|
|
119
123
|
- spec/support/helpers/add_word.rb
|
120
124
|
- spec/support/helpers/one_line_heredoc.rb
|
121
125
|
- spec/support/shared_examples/a_compressible_trie.rb
|
126
|
+
- spec/support/shared_examples/a_container_partial_word.rb
|
127
|
+
- spec/support/shared_examples/a_container_scan.rb
|
128
|
+
- spec/support/shared_examples/a_container_word.rb
|
129
|
+
- spec/support/shared_examples/a_container_words_within.rb
|
122
130
|
- spec/support/shared_examples/a_serializable_trie.rb
|
123
131
|
- spec/support/shared_examples/a_serializer.rb
|
124
132
|
- spec/support/shared_examples/a_trie_data_structure.rb
|
125
133
|
- spec/support/shared_examples/a_trie_node.rb
|
126
134
|
- spec/support/shared_examples/a_trie_node_implementation.rb
|
127
135
|
- spec/tmp/.gitkeep
|
128
|
-
homepage:
|
136
|
+
homepage: https://github.com/gonzedge/rambling-trie
|
129
137
|
licenses:
|
130
138
|
- MIT
|
131
|
-
metadata:
|
139
|
+
metadata:
|
140
|
+
changelog_uri: https://github.com/gonzedge/rambling-trie/blob/master/CHANGELOG.md
|
141
|
+
documentation_uri: https://www.rubydoc.info/gems/rambling-trie
|
132
142
|
post_install_message:
|
133
143
|
rdoc_options: []
|
134
144
|
require_paths:
|
@@ -147,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
157
|
- !ruby/object:Gem::Version
|
148
158
|
version: '0'
|
149
159
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
160
|
+
rubygems_version: 3.5.3
|
151
161
|
signing_key:
|
152
162
|
specification_version: 4
|
153
163
|
summary: A Ruby implementation of the trie data structure.
|
@@ -166,8 +176,10 @@ test_files:
|
|
166
176
|
- spec/lib/rambling/trie/nodes/node_spec.rb
|
167
177
|
- spec/lib/rambling/trie/nodes/raw_spec.rb
|
168
178
|
- spec/lib/rambling/trie/readers/plain_text_spec.rb
|
179
|
+
- spec/lib/rambling/trie/readers/reader_spec.rb
|
169
180
|
- spec/lib/rambling/trie/serializers/file_spec.rb
|
170
181
|
- spec/lib/rambling/trie/serializers/marshal_spec.rb
|
182
|
+
- spec/lib/rambling/trie/serializers/serializer_spec.rb
|
171
183
|
- spec/lib/rambling/trie/serializers/yaml_spec.rb
|
172
184
|
- spec/lib/rambling/trie/serializers/zip_spec.rb
|
173
185
|
- spec/lib/rambling/trie/stringifyable_spec.rb
|
@@ -177,6 +189,10 @@ test_files:
|
|
177
189
|
- spec/support/helpers/add_word.rb
|
178
190
|
- spec/support/helpers/one_line_heredoc.rb
|
179
191
|
- spec/support/shared_examples/a_compressible_trie.rb
|
192
|
+
- spec/support/shared_examples/a_container_partial_word.rb
|
193
|
+
- spec/support/shared_examples/a_container_scan.rb
|
194
|
+
- spec/support/shared_examples/a_container_word.rb
|
195
|
+
- spec/support/shared_examples/a_container_words_within.rb
|
180
196
|
- spec/support/shared_examples/a_serializable_trie.rb
|
181
197
|
- spec/support/shared_examples/a_serializer.rb
|
182
198
|
- spec/support/shared_examples/a_trie_data_structure.rb
|