rambling-trie 2.2.1 → 2.3.1

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -1
  3. data/LICENSE +1 -1
  4. data/README.md +37 -21
  5. data/lib/rambling/trie/comparable.rb +2 -2
  6. data/lib/rambling/trie/compressible.rb +3 -3
  7. data/lib/rambling/trie/configuration/properties.rb +10 -9
  8. data/lib/rambling/trie/configuration/provider_collection.rb +17 -15
  9. data/lib/rambling/trie/container.rb +18 -20
  10. data/lib/rambling/trie/enumerable.rb +4 -1
  11. data/lib/rambling/trie/nodes/compressed.rb +3 -3
  12. data/lib/rambling/trie/nodes/node.rb +18 -18
  13. data/lib/rambling/trie/nodes/raw.rb +2 -2
  14. data/lib/rambling/trie/readers/plain_text.rb +9 -4
  15. data/lib/rambling/trie/readers/reader.rb +21 -0
  16. data/lib/rambling/trie/readers.rb +1 -1
  17. data/lib/rambling/trie/serializers/file.rb +1 -1
  18. data/lib/rambling/trie/serializers/marshal.rb +6 -5
  19. data/lib/rambling/trie/serializers/serializer.rb +27 -0
  20. data/lib/rambling/trie/serializers/yaml.rb +7 -7
  21. data/lib/rambling/trie/serializers/zip.rb +9 -5
  22. data/lib/rambling/trie/serializers.rb +1 -1
  23. data/lib/rambling/trie/stringifyable.rb +1 -1
  24. data/lib/rambling/trie/version.rb +1 -1
  25. data/lib/rambling/trie.rb +12 -10
  26. data/rambling-trie.gemspec +8 -4
  27. data/spec/integration/rambling/trie_spec.rb +13 -16
  28. data/spec/lib/rambling/trie/comparable_spec.rb +29 -39
  29. data/spec/lib/rambling/trie/compressor_spec.rb +17 -14
  30. data/spec/lib/rambling/trie/configuration/properties_spec.rb +25 -7
  31. data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +42 -14
  32. data/spec/lib/rambling/trie/container_spec.rb +200 -325
  33. data/spec/lib/rambling/trie/enumerable_spec.rb +18 -10
  34. data/spec/lib/rambling/trie/inspectable_spec.rb +9 -3
  35. data/spec/lib/rambling/trie/nodes/node_spec.rb +1 -1
  36. data/spec/lib/rambling/trie/nodes/raw_spec.rb +26 -23
  37. data/spec/lib/rambling/trie/readers/plain_text_spec.rb +11 -1
  38. data/spec/lib/rambling/trie/readers/reader_spec.rb +14 -0
  39. data/spec/lib/rambling/trie/serializers/file_spec.rb +1 -3
  40. data/spec/lib/rambling/trie/serializers/marshal_spec.rb +1 -3
  41. data/spec/lib/rambling/trie/serializers/serializer_spec.rb +21 -0
  42. data/spec/lib/rambling/trie/serializers/yaml_spec.rb +1 -3
  43. data/spec/lib/rambling/trie/serializers/zip_spec.rb +24 -16
  44. data/spec/lib/rambling/trie/stringifyable_spec.rb +17 -13
  45. data/spec/lib/rambling/trie_spec.rb +106 -44
  46. data/spec/spec_helper.rb +14 -9
  47. data/spec/support/shared_examples/a_compressible_trie.rb +9 -3
  48. data/spec/support/shared_examples/a_container_partial_word.rb +17 -0
  49. data/spec/support/shared_examples/a_container_scan.rb +14 -0
  50. data/spec/support/shared_examples/a_container_word.rb +43 -0
  51. data/spec/support/shared_examples/a_container_words_within.rb +44 -0
  52. data/spec/support/shared_examples/a_serializable_trie.rb +4 -8
  53. data/spec/support/shared_examples/a_serializer.rb +36 -13
  54. data/spec/support/shared_examples/a_trie_data_structure.rb +24 -10
  55. data/spec/support/shared_examples/a_trie_node.rb +19 -12
  56. data/spec/support/shared_examples/a_trie_node_implementation.rb +40 -43
  57. metadata +26 -10
@@ -40,9 +40,7 @@ shared_examples_for 'a trie node' do
40
40
 
41
41
  describe '#root?' do
42
42
  context 'when the node has a parent' do
43
- before do
44
- node.parent = node
45
- end
43
+ before { node.parent = node }
46
44
 
47
45
  it 'returns false' do
48
46
  expect(node).not_to be_root
@@ -50,9 +48,7 @@ shared_examples_for 'a trie node' do
50
48
  end
51
49
 
52
50
  context 'when the node does not have a parent' do
53
- before do
54
- node.parent = nil
55
- end
51
+ before { node.parent = nil }
56
52
 
57
53
  it 'returns true' do
58
54
  expect(node).to be_root
@@ -61,12 +57,13 @@ shared_examples_for 'a trie node' do
61
57
  end
62
58
 
63
59
  describe '#terminal!' do
60
+ # rubocop:disable RSpec/MultipleExpectations
64
61
  it 'forces the node to be terminal' do
65
62
  expect(node).not_to be_terminal
66
63
  node.terminal!
67
-
68
64
  expect(node).to be_terminal
69
65
  end
66
+ # rubocop:enable RSpec/MultipleExpectations
70
67
 
71
68
  it 'returns the node' do
72
69
  expect(node.terminal!).to eq node
@@ -75,7 +72,8 @@ shared_examples_for 'a trie node' do
75
72
 
76
73
  describe 'delegates and aliases' do
77
74
  let(:children_tree) do
78
- double(
75
+ instance_double(
76
+ 'Hash',
79
77
  :children_tree,
80
78
  :[] => 'value',
81
79
  :[]= => nil,
@@ -84,20 +82,21 @@ shared_examples_for 'a trie node' do
84
82
  )
85
83
  end
86
84
 
87
- before do
88
- node.children_tree = children_tree
89
- end
85
+ before { node.children_tree = children_tree }
90
86
 
87
+ # rubocop:disable RSpec/MultipleExpectations
91
88
  it 'delegates `#[]` to its children tree' do
92
89
  expect(node[:key]).to eq 'value'
93
90
  expect(children_tree).to have_received(:[]).with :key
94
91
  end
92
+ # rubocop:enable RSpec/MultipleExpectations
95
93
 
96
94
  it 'delegates `#[]=` to its children tree' do
97
95
  node[:key] = 'value'
98
96
  expect(children_tree).to have_received(:[]=).with(:key, 'value')
99
97
  end
100
98
 
99
+ # rubocop:disable RSpec/MultipleExpectations
101
100
  it 'delegates `#key?` to its children tree' do
102
101
  allow(children_tree).to receive(:key?)
103
102
  .with(:present_key)
@@ -106,18 +105,26 @@ shared_examples_for 'a trie node' do
106
105
  expect(node).to have_key(:present_key)
107
106
  expect(node).not_to have_key(:absent_key)
108
107
  end
108
+ # rubocop:enable RSpec/MultipleExpectations
109
109
 
110
+ # rubocop:disable RSpec/MultipleExpectations
110
111
  it 'delegates `#delete` to its children tree' do
111
112
  expect(node.delete :key).to be true
112
113
  expect(children_tree).to have_received(:delete).with :key
113
114
  end
115
+ # rubocop:enable RSpec/MultipleExpectations
114
116
 
117
+ # rubocop:disable RSpec/ExampleLength
115
118
  it 'delegates `#children` to its children tree values' do
116
- children = [double(:child_1), double(:child_2)]
119
+ children = [
120
+ instance_double('Rambling::Trie::Nodes::Node', :child_one),
121
+ instance_double('Rambling::Trie::Nodes::Node', :child_two),
122
+ ]
117
123
  allow(children_tree).to receive(:values).and_return children
118
124
 
119
125
  expect(node.children).to eq children
120
126
  end
127
+ # rubocop:enable RSpec/ExampleLength
121
128
 
122
129
  it 'aliases `#has_key?` to `#key?`' do
123
130
  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 do
16
- add_word_to_tree 'abc'
17
- end
15
+ before { add_word_to_tree 'abc' }
18
16
 
19
- it 'returns true' do
20
- expect(node.partial_word? %w(a)).to be true
21
- expect(node.partial_word? %w(a b)).to be true
22
- expect(node.partial_word? %w(a b c)).to be true
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 do
28
- add_word_to_tree 'cba'
29
- end
25
+ before { add_word_to_tree 'cba' }
30
26
 
31
- it 'returns false' do
32
- expect(node.partial_word? %w(a)).to be false
33
- expect(node.partial_word? %w(a b)).to be false
34
- expect(node.partial_word? %w(a b c)).to be false
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 do
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 do
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 do
72
- add_word_to_tree 'abc'
73
- end
63
+ before { add_word_to_tree 'abc' }
74
64
 
75
- it 'returns false' do
76
- expect(node.word? %w(a).map(&:dup)).to be false
77
- expect(node.word? %w(a b).map(&:dup)).to be false
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 do
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
- it 'returns the found child' do
97
- expect(node.scan %w(c)).to match_array %w(cba ccab)
98
- expect(node.scan %w(c b)).to match_array %w(cba)
99
- expect(node.scan %w(c b a)).to match_array %w(cba)
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
- it 'returns a Nodes::Missing' do
105
- expect(node.scan %w(a)).to be_a Rambling::Trie::Nodes::Missing
106
- expect(node.scan %w(a b)).to be_a Rambling::Trie::Nodes::Missing
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
110
- expect(node.scan %w(c b a d)).to be_a Rambling::Trie::Nodes::Missing
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 do
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.2.1
4
+ version: 2.3.1
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: 2021-06-18 00:00:00.000000000 Z
12
+ date: 2023-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -31,28 +31,28 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '3.9'
34
+ version: '3.12'
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: '3.9'
41
+ version: '3.12'
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.25
48
+ version: 0.9.28
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.25
55
+ version: 0.9.28
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,6 +123,10 @@ 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
@@ -128,7 +136,9 @@ files:
128
136
  homepage: http://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:
@@ -137,17 +147,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
147
  requirements:
138
148
  - - ">="
139
149
  - !ruby/object:Gem::Version
140
- version: '2.5'
150
+ version: '2.7'
141
151
  - - "<"
142
152
  - !ruby/object:Gem::Version
143
- version: '3.1'
153
+ version: '4'
144
154
  required_rubygems_version: !ruby/object:Gem::Requirement
145
155
  requirements:
146
156
  - - ">="
147
157
  - !ruby/object:Gem::Version
148
158
  version: '0'
149
159
  requirements: []
150
- rubygems_version: 3.2.15
160
+ rubygems_version: 3.4.10
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