rambling-trie-opal 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +26 -0
- data/Guardfile +10 -0
- data/LICENSE +26 -0
- data/README.md +301 -0
- data/Rakefile +15 -0
- data/lib/rambling-trie.rb +3 -0
- data/lib/rambling/trie.rb +119 -0
- data/lib/rambling/trie/comparable.rb +19 -0
- data/lib/rambling/trie/compressible.rb +16 -0
- data/lib/rambling/trie/compressor.rb +64 -0
- data/lib/rambling/trie/configuration.rb +16 -0
- data/lib/rambling/trie/configuration/properties.rb +75 -0
- data/lib/rambling/trie/configuration/provider_collection.rb +122 -0
- data/lib/rambling/trie/container.rb +226 -0
- data/lib/rambling/trie/enumerable.rb +29 -0
- data/lib/rambling/trie/inspectable.rb +39 -0
- data/lib/rambling/trie/invalid_operation.rb +15 -0
- data/lib/rambling/trie/nodes.rb +18 -0
- data/lib/rambling/trie/nodes/compressed.rb +98 -0
- data/lib/rambling/trie/nodes/missing.rb +12 -0
- data/lib/rambling/trie/nodes/node.rb +183 -0
- data/lib/rambling/trie/nodes/raw.rb +82 -0
- data/lib/rambling/trie/readers.rb +15 -0
- data/lib/rambling/trie/readers/plain_text.rb +18 -0
- data/lib/rambling/trie/serializers.rb +18 -0
- data/lib/rambling/trie/serializers/file.rb +27 -0
- data/lib/rambling/trie/serializers/marshal.rb +48 -0
- data/lib/rambling/trie/serializers/yaml.rb +55 -0
- data/lib/rambling/trie/serializers/zip.rb +74 -0
- data/lib/rambling/trie/stringifyable.rb +26 -0
- data/lib/rambling/trie/version.rb +8 -0
- data/rambling-trie-opal.gemspec +36 -0
- data/spec/assets/test_words.en_US.txt +23 -0
- data/spec/assets/test_words.es_DO.txt +24 -0
- data/spec/integration/rambling/trie_spec.rb +87 -0
- data/spec/lib/rambling/trie/comparable_spec.rb +97 -0
- data/spec/lib/rambling/trie/compressor_spec.rb +108 -0
- data/spec/lib/rambling/trie/configuration/properties_spec.rb +57 -0
- data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +149 -0
- data/spec/lib/rambling/trie/container_spec.rb +591 -0
- data/spec/lib/rambling/trie/enumerable_spec.rb +42 -0
- data/spec/lib/rambling/trie/inspectable_spec.rb +56 -0
- data/spec/lib/rambling/trie/nodes/compressed_spec.rb +37 -0
- data/spec/lib/rambling/trie/nodes/node_spec.rb +9 -0
- data/spec/lib/rambling/trie/nodes/raw_spec.rb +179 -0
- data/spec/lib/rambling/trie/readers/plain_text_spec.rb +16 -0
- data/spec/lib/rambling/trie/serializers/file_spec.rb +13 -0
- data/spec/lib/rambling/trie/serializers/marshal_spec.rb +12 -0
- data/spec/lib/rambling/trie/serializers/yaml_spec.rb +12 -0
- data/spec/lib/rambling/trie/serializers/zip_spec.rb +28 -0
- data/spec/lib/rambling/trie/stringifyable_spec.rb +85 -0
- data/spec/lib/rambling/trie_spec.rb +182 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/config.rb +15 -0
- data/spec/support/helpers/add_word.rb +20 -0
- data/spec/support/helpers/one_line_heredoc.rb +11 -0
- data/spec/support/shared_examples/a_compressible_trie.rb +40 -0
- data/spec/support/shared_examples/a_serializable_trie.rb +30 -0
- data/spec/support/shared_examples/a_serializer.rb +37 -0
- data/spec/support/shared_examples/a_trie_data_structure.rb +31 -0
- data/spec/support/shared_examples/a_trie_node.rb +127 -0
- data/spec/support/shared_examples/a_trie_node_implementation.rb +152 -0
- data/spec/tmp/.gitkeep +0 -0
- metadata +179 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples_for 'a trie node implementation' do
|
4
|
+
it_behaves_like 'a trie node'
|
5
|
+
|
6
|
+
describe '#partial_word?' do
|
7
|
+
context 'when the chars array is empty' do
|
8
|
+
it 'returns true' do
|
9
|
+
expect(node.partial_word? []).to be true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when the chars array is not empty' do
|
14
|
+
context 'when the node has a tree that matches the characters' do
|
15
|
+
before do
|
16
|
+
add_word_to_tree 'abc'
|
17
|
+
end
|
18
|
+
|
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
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
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
|
30
|
+
|
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
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#word?' do
|
41
|
+
context 'when the chars array is empty' do
|
42
|
+
context 'when the node is terminal' do
|
43
|
+
before do
|
44
|
+
node.terminal!
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns true' do
|
48
|
+
expect(node.word? []).to be true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when the node is not terminal' do
|
53
|
+
it 'returns false' do
|
54
|
+
expect(node.word? []).to be false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when the chars array is not empty' do
|
60
|
+
context 'when the node has a tree that matches all the characters' do
|
61
|
+
before do
|
62
|
+
add_word_to_tree 'abc'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns true' do
|
66
|
+
expect(node.word? %w(a b c).map(&:dup)).to be true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when the node subtree does not match all the characters' do
|
71
|
+
before do
|
72
|
+
add_word_to_tree 'abc'
|
73
|
+
end
|
74
|
+
|
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
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#scan' do
|
84
|
+
context 'when the chars array is empty' do
|
85
|
+
it 'returns itself' do
|
86
|
+
expect(node.scan []).to eq node
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when the chars array is not empty' do
|
91
|
+
before do
|
92
|
+
add_words_to_tree %w(cba ccab)
|
93
|
+
end
|
94
|
+
|
95
|
+
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)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
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
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#match_prefix' do
|
117
|
+
before do
|
118
|
+
assign_letter :i
|
119
|
+
add_words_to_tree %w(gnite mport mportant mportantly)
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'when the node is terminal' do
|
123
|
+
before do
|
124
|
+
node.terminal!
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'adds itself to the words' do
|
128
|
+
expect(node.match_prefix %w(g n i t e)).to include 'i'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when the node is not terminal' do
|
133
|
+
it 'does not add itself to the words' do
|
134
|
+
expect(node.match_prefix %w(g n i t e)).not_to include 'i'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'when the first few chars match a terminal node' do
|
139
|
+
it 'adds those terminal nodes to the words' do
|
140
|
+
words = node.match_prefix(%w(m p o r t a n t l y)).to_a
|
141
|
+
expect(words).to include 'import', 'important', 'importantly'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when the first few chars do not match a terminal node' do
|
146
|
+
it 'does not add any other words found' do
|
147
|
+
words = node.match_prefix(%w(m p m p o r t a n t l y)).to_a
|
148
|
+
expect(words).not_to include 'import', 'important', 'importantly'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
data/spec/tmp/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rambling-trie-opal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.25
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.25
|
55
|
+
description: 'The original Rambling Trie gem but Opal-compatible. '
|
56
|
+
email:
|
57
|
+
- open.source@ribose.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- Guardfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/rambling-trie.rb
|
68
|
+
- lib/rambling/trie.rb
|
69
|
+
- lib/rambling/trie/comparable.rb
|
70
|
+
- lib/rambling/trie/compressible.rb
|
71
|
+
- lib/rambling/trie/compressor.rb
|
72
|
+
- lib/rambling/trie/configuration.rb
|
73
|
+
- lib/rambling/trie/configuration/properties.rb
|
74
|
+
- lib/rambling/trie/configuration/provider_collection.rb
|
75
|
+
- lib/rambling/trie/container.rb
|
76
|
+
- lib/rambling/trie/enumerable.rb
|
77
|
+
- lib/rambling/trie/inspectable.rb
|
78
|
+
- lib/rambling/trie/invalid_operation.rb
|
79
|
+
- lib/rambling/trie/nodes.rb
|
80
|
+
- lib/rambling/trie/nodes/compressed.rb
|
81
|
+
- lib/rambling/trie/nodes/missing.rb
|
82
|
+
- lib/rambling/trie/nodes/node.rb
|
83
|
+
- lib/rambling/trie/nodes/raw.rb
|
84
|
+
- lib/rambling/trie/readers.rb
|
85
|
+
- lib/rambling/trie/readers/plain_text.rb
|
86
|
+
- lib/rambling/trie/serializers.rb
|
87
|
+
- lib/rambling/trie/serializers/file.rb
|
88
|
+
- lib/rambling/trie/serializers/marshal.rb
|
89
|
+
- lib/rambling/trie/serializers/yaml.rb
|
90
|
+
- lib/rambling/trie/serializers/zip.rb
|
91
|
+
- lib/rambling/trie/stringifyable.rb
|
92
|
+
- lib/rambling/trie/version.rb
|
93
|
+
- rambling-trie-opal.gemspec
|
94
|
+
- spec/assets/test_words.en_US.txt
|
95
|
+
- spec/assets/test_words.es_DO.txt
|
96
|
+
- spec/integration/rambling/trie_spec.rb
|
97
|
+
- spec/lib/rambling/trie/comparable_spec.rb
|
98
|
+
- spec/lib/rambling/trie/compressor_spec.rb
|
99
|
+
- spec/lib/rambling/trie/configuration/properties_spec.rb
|
100
|
+
- spec/lib/rambling/trie/configuration/provider_collection_spec.rb
|
101
|
+
- spec/lib/rambling/trie/container_spec.rb
|
102
|
+
- spec/lib/rambling/trie/enumerable_spec.rb
|
103
|
+
- spec/lib/rambling/trie/inspectable_spec.rb
|
104
|
+
- spec/lib/rambling/trie/nodes/compressed_spec.rb
|
105
|
+
- spec/lib/rambling/trie/nodes/node_spec.rb
|
106
|
+
- spec/lib/rambling/trie/nodes/raw_spec.rb
|
107
|
+
- spec/lib/rambling/trie/readers/plain_text_spec.rb
|
108
|
+
- spec/lib/rambling/trie/serializers/file_spec.rb
|
109
|
+
- spec/lib/rambling/trie/serializers/marshal_spec.rb
|
110
|
+
- spec/lib/rambling/trie/serializers/yaml_spec.rb
|
111
|
+
- spec/lib/rambling/trie/serializers/zip_spec.rb
|
112
|
+
- spec/lib/rambling/trie/stringifyable_spec.rb
|
113
|
+
- spec/lib/rambling/trie_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
- spec/support/config.rb
|
116
|
+
- spec/support/helpers/add_word.rb
|
117
|
+
- spec/support/helpers/one_line_heredoc.rb
|
118
|
+
- spec/support/shared_examples/a_compressible_trie.rb
|
119
|
+
- spec/support/shared_examples/a_serializable_trie.rb
|
120
|
+
- spec/support/shared_examples/a_serializer.rb
|
121
|
+
- spec/support/shared_examples/a_trie_data_structure.rb
|
122
|
+
- spec/support/shared_examples/a_trie_node.rb
|
123
|
+
- spec/support/shared_examples/a_trie_node_implementation.rb
|
124
|
+
- spec/tmp/.gitkeep
|
125
|
+
homepage: http://github.com/interscript/rambling-trie
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '2.4'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubygems_version: 3.0.3
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: A Ruby implementation (Opal Compatible) of the trie data structure.
|
148
|
+
test_files:
|
149
|
+
- spec/assets/test_words.en_US.txt
|
150
|
+
- spec/assets/test_words.es_DO.txt
|
151
|
+
- spec/integration/rambling/trie_spec.rb
|
152
|
+
- spec/lib/rambling/trie/comparable_spec.rb
|
153
|
+
- spec/lib/rambling/trie/compressor_spec.rb
|
154
|
+
- spec/lib/rambling/trie/configuration/properties_spec.rb
|
155
|
+
- spec/lib/rambling/trie/configuration/provider_collection_spec.rb
|
156
|
+
- spec/lib/rambling/trie/container_spec.rb
|
157
|
+
- spec/lib/rambling/trie/enumerable_spec.rb
|
158
|
+
- spec/lib/rambling/trie/inspectable_spec.rb
|
159
|
+
- spec/lib/rambling/trie/nodes/compressed_spec.rb
|
160
|
+
- spec/lib/rambling/trie/nodes/node_spec.rb
|
161
|
+
- spec/lib/rambling/trie/nodes/raw_spec.rb
|
162
|
+
- spec/lib/rambling/trie/readers/plain_text_spec.rb
|
163
|
+
- spec/lib/rambling/trie/serializers/file_spec.rb
|
164
|
+
- spec/lib/rambling/trie/serializers/marshal_spec.rb
|
165
|
+
- spec/lib/rambling/trie/serializers/yaml_spec.rb
|
166
|
+
- spec/lib/rambling/trie/serializers/zip_spec.rb
|
167
|
+
- spec/lib/rambling/trie/stringifyable_spec.rb
|
168
|
+
- spec/lib/rambling/trie_spec.rb
|
169
|
+
- spec/spec_helper.rb
|
170
|
+
- spec/support/config.rb
|
171
|
+
- spec/support/helpers/add_word.rb
|
172
|
+
- spec/support/helpers/one_line_heredoc.rb
|
173
|
+
- spec/support/shared_examples/a_compressible_trie.rb
|
174
|
+
- spec/support/shared_examples/a_serializable_trie.rb
|
175
|
+
- spec/support/shared_examples/a_serializer.rb
|
176
|
+
- spec/support/shared_examples/a_trie_data_structure.rb
|
177
|
+
- spec/support/shared_examples/a_trie_node.rb
|
178
|
+
- spec/support/shared_examples/a_trie_node_implementation.rb
|
179
|
+
- spec/tmp/.gitkeep
|