rambling-trie 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +6 -4
  3. data/Guardfile +3 -1
  4. data/README.md +4 -4
  5. data/Rakefile +4 -0
  6. data/lib/rambling-trie.rb +2 -0
  7. data/lib/rambling/trie.rb +25 -9
  8. data/lib/rambling/trie/comparable.rb +4 -1
  9. data/lib/rambling/trie/compressible.rb +6 -4
  10. data/lib/rambling/trie/compressor.rb +12 -10
  11. data/lib/rambling/trie/configuration.rb +3 -1
  12. data/lib/rambling/trie/configuration/properties.rb +15 -8
  13. data/lib/rambling/trie/configuration/provider_collection.rb +4 -1
  14. data/lib/rambling/trie/container.rb +7 -40
  15. data/lib/rambling/trie/enumerable.rb +2 -0
  16. data/lib/rambling/trie/inspectable.rb +2 -0
  17. data/lib/rambling/trie/invalid_operation.rb +3 -1
  18. data/lib/rambling/trie/nodes.rb +3 -1
  19. data/lib/rambling/trie/nodes/compressed.rb +53 -70
  20. data/lib/rambling/trie/nodes/missing.rb +2 -0
  21. data/lib/rambling/trie/nodes/node.rb +38 -6
  22. data/lib/rambling/trie/nodes/raw.rb +19 -26
  23. data/lib/rambling/trie/readers.rb +3 -1
  24. data/lib/rambling/trie/readers/plain_text.rb +2 -0
  25. data/lib/rambling/trie/serializers.rb +3 -1
  26. data/lib/rambling/trie/serializers/file.rb +2 -0
  27. data/lib/rambling/trie/serializers/marshal.rb +12 -2
  28. data/lib/rambling/trie/serializers/yaml.rb +18 -2
  29. data/lib/rambling/trie/serializers/zip.rb +6 -0
  30. data/lib/rambling/trie/stringifyable.rb +7 -1
  31. data/lib/rambling/trie/version.rb +3 -1
  32. data/rambling-trie.gemspec +21 -10
  33. data/spec/integration/rambling/trie_spec.rb +8 -4
  34. data/spec/lib/rambling/trie/comparable_spec.rb +2 -0
  35. data/spec/lib/rambling/trie/compressor_spec.rb +35 -33
  36. data/spec/lib/rambling/trie/configuration/properties_spec.rb +17 -9
  37. data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +10 -14
  38. data/spec/lib/rambling/trie/container_spec.rb +28 -53
  39. data/spec/lib/rambling/trie/enumerable_spec.rb +2 -0
  40. data/spec/lib/rambling/trie/inspectable_spec.rb +32 -7
  41. data/spec/lib/rambling/trie/nodes/compressed_spec.rb +2 -0
  42. data/spec/lib/rambling/trie/nodes/node_spec.rb +2 -0
  43. data/spec/lib/rambling/trie/nodes/raw_spec.rb +2 -0
  44. data/spec/lib/rambling/trie/readers/plain_text_spec.rb +3 -1
  45. data/spec/lib/rambling/trie/serializers/file_spec.rb +2 -0
  46. data/spec/lib/rambling/trie/serializers/marshal_spec.rb +2 -0
  47. data/spec/lib/rambling/trie/serializers/yaml_spec.rb +2 -0
  48. data/spec/lib/rambling/trie/serializers/zip_spec.rb +6 -4
  49. data/spec/lib/rambling/trie/stringifyable_spec.rb +7 -3
  50. data/spec/lib/rambling/trie_spec.rb +16 -9
  51. data/spec/spec_helper.rb +10 -7
  52. data/spec/support/config.rb +6 -0
  53. data/spec/support/helpers/add_word.rb +2 -0
  54. data/spec/support/helpers/one_line_heredoc.rb +11 -0
  55. data/spec/support/shared_examples/a_compressible_trie.rb +7 -3
  56. data/spec/support/shared_examples/a_serializable_trie.rb +2 -0
  57. data/spec/support/shared_examples/a_serializer.rb +2 -0
  58. data/spec/support/shared_examples/a_trie_data_structure.rb +2 -0
  59. data/spec/support/shared_examples/a_trie_node.rb +15 -5
  60. data/spec/support/shared_examples/a_trie_node_implementation.rb +10 -6
  61. metadata +17 -15
@@ -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
- require 'support/shared_examples/a_compressible_trie'
30
- require 'support/shared_examples/a_serializable_trie'
31
- require 'support/shared_examples/a_serializer'
32
- require 'support/shared_examples/a_trie_data_structure'
33
- require 'support/shared_examples/a_trie_node'
34
- require 'support/shared_examples/a_trie_node_implementation'
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
@@ -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
  module Support
2
4
  module Helpers
3
5
  module AddWord
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Support
4
+ module Helpers
5
+ module OneLineHeredoc
6
+ def one_line heredoc
7
+ heredoc.strip.tr "\n", ' '
8
+ end
9
+ end
10
+ end
11
+ 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!(:original_tree) { original_root.children_tree.keys }
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 original_tree
33
- expect(trie.children_tree.keys).not_to eq original_tree
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 serializable trie' do
2
4
  let(:tmp_path) { File.join ::SPEC_ROOT, 'tmp' }
3
5
  let(:filepath) { File.join tmp_path, "trie-root.#{format}" }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples_for 'a serializer' do
2
4
  let(:trie) { Rambling::Trie.create }
3
5
  let(:tmp_path) { File.join ::SPEC_ROOT, 'tmp' }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples_for 'a trie data structure' do
2
4
  it 'contains all the words previously provided' do
3
5
  words.each do |word|
@@ -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 :children_tree, {
78
+ double(
79
+ :children_tree,
77
80
  :[] => 'value',
78
81
  :[]= => nil,
79
- has_key?: false,
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 `#has_key?` to its children tree' do
99
- allow(children_tree).to receive(:has_key?).with(:present_key).and_return true
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 has a tree that does not match all the characters' do
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
- add_word_to_tree 'cba'
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: 1.0.3
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-04-07 00:00:00.000000000 Z
12
+ date: 2018-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rspec
15
+ name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '3.5'
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.5'
27
+ version: '12.3'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
29
+ name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '12.0'
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: '12.0'
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.5
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.5
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: '0'
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.14
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