rambling-trie 2.4.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +28 -0
- data/Gemfile +20 -8
- data/Guardfile +16 -5
- data/README.md +38 -32
- data/Rakefile +6 -0
- data/Steepfile +35 -0
- data/lib/rambling/trie/comparable.rb +2 -2
- data/lib/rambling/trie/compressible.rb +1 -1
- data/lib/rambling/trie/compressor.rb +22 -19
- data/lib/rambling/trie/configuration/properties.rb +10 -6
- data/lib/rambling/trie/configuration/provider_collection.rb +14 -9
- data/lib/rambling/trie/configuration.rb +2 -3
- data/lib/rambling/trie/container.rb +32 -24
- data/lib/rambling/trie/enumerable.rb +5 -6
- data/lib/rambling/trie/nodes/compressed.rb +26 -16
- data/lib/rambling/trie/nodes/node.rb +35 -12
- data/lib/rambling/trie/nodes/raw.rb +18 -20
- data/lib/rambling/trie/nodes.rb +2 -3
- data/lib/rambling/trie/readers/plain_text.rb +3 -3
- data/lib/rambling/trie/readers.rb +2 -3
- data/lib/rambling/trie/serializers/file.rb +1 -3
- data/lib/rambling/trie/serializers/marshal.rb +4 -4
- data/lib/rambling/trie/serializers/yaml.rb +3 -3
- data/lib/rambling/trie/serializers/zip.rb +13 -5
- data/lib/rambling/trie/serializers.rb +2 -3
- data/lib/rambling/trie/stringifyable.rb +1 -1
- data/lib/rambling/trie/version.rb +1 -1
- data/lib/rambling/trie.rb +12 -15
- data/rambling-trie.gemspec +4 -10
- data/sig/lib/rambling/trie/comparable.rbs +17 -0
- data/sig/lib/rambling/trie/compressible.rbs +17 -0
- data/sig/lib/rambling/trie/compressor.rbs +17 -0
- data/sig/lib/rambling/trie/configuration/properties.rbs +28 -0
- data/sig/lib/rambling/trie/configuration/provider_collection.rbs +47 -0
- data/sig/lib/rambling/trie/container.rbs +69 -0
- data/sig/lib/rambling/trie/enumerable.rbs +23 -0
- data/sig/lib/rambling/trie/inspectable.rbs +27 -0
- data/sig/lib/rambling/trie/invalid_operation.rbs +7 -0
- data/sig/lib/rambling/trie/nodes/compressed.rbs +25 -0
- data/sig/lib/rambling/trie/nodes/missing.rbs +9 -0
- data/sig/lib/rambling/trie/nodes/node.rbs +69 -0
- data/sig/lib/rambling/trie/nodes/raw.rbs +27 -0
- data/sig/lib/rambling/trie/readers/plain_text.rbs +9 -0
- data/sig/lib/rambling/trie/readers/reader.rbs +9 -0
- data/sig/lib/rambling/trie/serializers/file.rbs +8 -0
- data/sig/lib/rambling/trie/serializers/marshal.rbs +13 -0
- data/sig/lib/rambling/trie/serializers/serializer.rbs +10 -0
- data/sig/lib/rambling/trie/serializers/yaml.rbs +13 -0
- data/sig/lib/rambling/trie/serializers/zip.rbs +21 -0
- data/sig/lib/rambling/trie/stringifyable.rbs +21 -0
- data/sig/lib/rambling/trie.rbs +27 -0
- data/sig/lib/zip/entry.rbs +11 -0
- data/sig/lib/zip/file.rbs +11 -0
- metadata +34 -123
- data/spec/assets/test_words.en_US.txt +0 -23
- data/spec/assets/test_words.es_DO.txt +0 -24
- data/spec/integration/rambling/trie_spec.rb +0 -116
- data/spec/lib/rambling/trie/comparable_spec.rb +0 -87
- data/spec/lib/rambling/trie/compressor_spec.rb +0 -111
- data/spec/lib/rambling/trie/configuration/properties_spec.rb +0 -75
- data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +0 -177
- data/spec/lib/rambling/trie/container_spec.rb +0 -466
- data/spec/lib/rambling/trie/enumerable_spec.rb +0 -50
- data/spec/lib/rambling/trie/inspectable_spec.rb +0 -62
- data/spec/lib/rambling/trie/nodes/compressed_spec.rb +0 -43
- data/spec/lib/rambling/trie/nodes/node_spec.rb +0 -9
- data/spec/lib/rambling/trie/nodes/raw_spec.rb +0 -184
- data/spec/lib/rambling/trie/readers/plain_text_spec.rb +0 -26
- data/spec/lib/rambling/trie/readers/reader_spec.rb +0 -14
- data/spec/lib/rambling/trie/serializers/file_spec.rb +0 -11
- data/spec/lib/rambling/trie/serializers/marshal_spec.rb +0 -10
- data/spec/lib/rambling/trie/serializers/serializer_spec.rb +0 -21
- data/spec/lib/rambling/trie/serializers/yaml_spec.rb +0 -10
- data/spec/lib/rambling/trie/serializers/zip_spec.rb +0 -36
- data/spec/lib/rambling/trie/stringifyable_spec.rb +0 -89
- data/spec/lib/rambling/trie_spec.rb +0 -244
- data/spec/spec_helper.rb +0 -42
- data/spec/support/config.rb +0 -15
- data/spec/support/helpers/add_word.rb +0 -20
- data/spec/support/helpers/one_line_heredoc.rb +0 -11
- data/spec/support/shared_examples/a_compressible_trie.rb +0 -46
- data/spec/support/shared_examples/a_container_partial_word.rb +0 -17
- data/spec/support/shared_examples/a_container_scan.rb +0 -14
- data/spec/support/shared_examples/a_container_word.rb +0 -43
- data/spec/support/shared_examples/a_container_words_within.rb +0 -44
- data/spec/support/shared_examples/a_serializable_trie.rb +0 -26
- data/spec/support/shared_examples/a_serializer.rb +0 -60
- data/spec/support/shared_examples/a_trie_data_structure.rb +0 -45
- data/spec/support/shared_examples/a_trie_node.rb +0 -135
- data/spec/support/shared_examples/a_trie_node_implementation.rb +0 -149
- data/spec/tmp/.gitkeep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c38f152f6ffdb5b7c3f5abde873ae3024651a52a7697fa4e706d01e28fe504e
|
4
|
+
data.tar.gz: 8cdec337b99995019a24d702b48dce2ee3e9a9e6acde298cd5cfef8086e93bc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bbadda2f93e7efdae19f0db8749e304be56b288d62095a269904c4d6e3b6e2f7723acba618fd4e8e8de416108ca9e6249c7a6c9ce5a70e70036e6ad287cb7e2
|
7
|
+
data.tar.gz: b60a49628ba61bca14d5a92573df83203feb0346d306adbc628ab7dfad54da82574902ee1f4985a365582a6c5a285b788a108ee7e7d2c22b0ce3f06dc5eccf78
|
data/Dockerfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
FROM ruby:3.3.6
|
2
|
+
|
3
|
+
RUN bundle config --global frozen 1
|
4
|
+
|
5
|
+
WORKDIR /usr/rambling-trie
|
6
|
+
RUN git init
|
7
|
+
|
8
|
+
# Copy strictly what is necessary to install dependencies
|
9
|
+
COPY Gemfile Gemfile.lock rambling-trie.gemspec ./
|
10
|
+
COPY lib ./lib
|
11
|
+
|
12
|
+
# Install dependencies
|
13
|
+
RUN bundle install
|
14
|
+
|
15
|
+
# Copy rest of Ruby and Markdown files
|
16
|
+
COPY Rakefile ./
|
17
|
+
COPY *.md ./
|
18
|
+
COPY assets ./assets
|
19
|
+
COPY sig ./sig
|
20
|
+
COPY spec ./spec
|
21
|
+
COPY tasks ./tasks
|
22
|
+
COPY scripts ./scripts
|
23
|
+
|
24
|
+
# Copy rest of configuration files
|
25
|
+
COPY *file ./
|
26
|
+
COPY *.yml ./
|
27
|
+
COPY .mdl* ./
|
28
|
+
COPY .yardopts ./
|
data/Gemfile
CHANGED
@@ -7,26 +7,38 @@ gemspec
|
|
7
7
|
gem 'rubyzip'
|
8
8
|
|
9
9
|
group :development do
|
10
|
-
gem '
|
11
|
-
gem '
|
12
|
-
gem 'memory_profiler'
|
13
|
-
gem 'pry'
|
14
|
-
gem 'ruby-prof'
|
15
|
-
gem 'stackprof'
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
16
12
|
end
|
17
13
|
|
18
14
|
group :test do
|
19
|
-
gem 'coveralls_reborn',
|
15
|
+
gem 'coveralls_reborn', require: false
|
20
16
|
gem 'rspec_junit_formatter'
|
21
17
|
gem 'simplecov', require: false
|
22
18
|
end
|
23
19
|
|
24
20
|
group :local do
|
21
|
+
gem 'benchmark-ips', require: false
|
22
|
+
gem 'flamegraph', require: false
|
25
23
|
gem 'flog', require: false
|
26
|
-
gem 'guard
|
24
|
+
gem 'guard', require: false
|
25
|
+
gem 'guard-reek', require: false
|
26
|
+
gem 'guard-rspec', require: false
|
27
|
+
gem 'guard-rubocop', require: false
|
28
|
+
gem 'guard-yard', require: false
|
27
29
|
gem 'mdl', require: false
|
30
|
+
gem 'memory_profiler', require: false
|
31
|
+
gem 'pry', require: false
|
32
|
+
gem 'racc', require: false
|
33
|
+
gem 'rbs', require: false
|
34
|
+
gem 'redcarpet', require: false
|
35
|
+
gem 'reek', require: false
|
28
36
|
gem 'rubocop', require: false
|
29
37
|
gem 'rubocop-performance', require: false
|
30
38
|
gem 'rubocop-rake', require: false
|
31
39
|
gem 'rubocop-rspec', require: false
|
40
|
+
gem 'ruby-prof', require: false
|
41
|
+
gem 'stackprof', require: false
|
42
|
+
gem 'steep', require: false
|
43
|
+
gem 'yard', require: false
|
32
44
|
end
|
data/Guardfile
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
# More info at https://github.com/guard/guard#readme
|
3
|
+
LIB_REGEX = %r{^lib/(.+)\.rb$}
|
5
4
|
|
6
|
-
guard
|
5
|
+
guard :reek, all_on_start: true, run_all: true do
|
6
|
+
watch(LIB_REGEX)
|
7
|
+
end
|
8
|
+
|
9
|
+
guard :rspec, cmd: 'rspec', all_on_start: true, all_after_pass: false do
|
7
10
|
watch(%r{^spec/.+_spec\.rb$})
|
8
|
-
watch(
|
9
|
-
watch('spec/spec_helper.rb')
|
11
|
+
watch(LIB_REGEX) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
12
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
13
|
+
end
|
14
|
+
|
15
|
+
guard :rubocop, all_on_start: true do
|
16
|
+
watch(LIB_REGEX)
|
17
|
+
end
|
18
|
+
|
19
|
+
guard :yard, server: false do
|
20
|
+
watch(LIB_REGEX)
|
10
21
|
end
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ and is designed to be very fast to traverse.
|
|
21
21
|
|
22
22
|
You will need:
|
23
23
|
|
24
|
-
* Ruby
|
24
|
+
* Ruby 3.1.0 or up
|
25
25
|
* RubyGems
|
26
26
|
|
27
27
|
See [RVM][rvm], [rbenv][rbenv] or [chruby][chruby] for more information on how to manage Ruby versions.
|
@@ -30,13 +30,13 @@ See [RVM][rvm], [rbenv][rbenv] or [chruby][chruby] for more information on how t
|
|
30
30
|
|
31
31
|
You can either install it manually with:
|
32
32
|
|
33
|
-
```
|
33
|
+
```shell
|
34
34
|
gem install rambling-trie
|
35
35
|
```
|
36
36
|
|
37
37
|
Or, include it in your `Gemfile` and bundle it:
|
38
38
|
|
39
|
-
```
|
39
|
+
```ruby
|
40
40
|
gem 'rambling-trie'
|
41
41
|
```
|
42
42
|
|
@@ -46,13 +46,13 @@ gem 'rambling-trie'
|
|
46
46
|
|
47
47
|
To create a new trie, initialize it like this:
|
48
48
|
|
49
|
-
```
|
49
|
+
```ruby
|
50
50
|
trie = Rambling::Trie.create
|
51
51
|
```
|
52
52
|
|
53
53
|
You can also provide a block and the created trie instance will be yielded for you to perform any operation on it:
|
54
54
|
|
55
|
-
```
|
55
|
+
```ruby
|
56
56
|
Rambling::Trie.create do |trie|
|
57
57
|
trie << 'word'
|
58
58
|
end
|
@@ -61,13 +61,13 @@ end
|
|
61
61
|
Additionally, you can provide the path to a file that contains all the words to be added to the trie, and it will read
|
62
62
|
the file and create the complete structure for you, like this:
|
63
63
|
|
64
|
-
```
|
64
|
+
```ruby
|
65
65
|
trie = Rambling::Trie.create '/path/to/file'
|
66
66
|
```
|
67
67
|
|
68
68
|
By default, a plain text file with the following format will be expected:
|
69
69
|
|
70
|
-
```
|
70
|
+
```text
|
71
71
|
some
|
72
72
|
words
|
73
73
|
to
|
@@ -85,20 +85,26 @@ readers.
|
|
85
85
|
|
86
86
|
To add new words to the trie, use `#add` or its alias `#<<`:
|
87
87
|
|
88
|
-
```
|
88
|
+
```ruby
|
89
89
|
trie.add 'word'
|
90
90
|
trie << 'word'
|
91
91
|
```
|
92
92
|
|
93
|
-
Or if you have multiple words to add, you can use `#concat`:
|
93
|
+
Or if you have multiple words to add, you can use `#concat` or `#push`:
|
94
94
|
|
95
|
-
```
|
95
|
+
```ruby
|
96
96
|
trie.concat %w(a collection of words)
|
97
|
+
trie.push 'a', 'collection', 'of', 'words'
|
98
|
+
|
99
|
+
# or
|
100
|
+
words = %w(a collection of words)
|
101
|
+
trie.concat words
|
102
|
+
trie.push *words
|
97
103
|
```
|
98
104
|
|
99
105
|
And to find out if a word already exists in the trie, use `#word?` or its alias `#include?`:
|
100
106
|
|
101
|
-
```
|
107
|
+
```ruby
|
102
108
|
trie.word? 'word'
|
103
109
|
trie.include? 'word'
|
104
110
|
```
|
@@ -106,21 +112,21 @@ trie.include? 'word'
|
|
106
112
|
If you wish to find if part of a word exists in the trie instance, you should call `#partial_word?` or its
|
107
113
|
alias `#match?`:
|
108
114
|
|
109
|
-
```
|
115
|
+
```ruby
|
110
116
|
trie.partial_word? 'partial_word'
|
111
117
|
trie.match? 'partial_word'
|
112
118
|
```
|
113
119
|
|
114
120
|
To get all the words that start with a particular string, you can use `#scan` or its alias `#words`:
|
115
121
|
|
116
|
-
```
|
122
|
+
```ruby
|
117
123
|
trie.scan 'hi' # => ['hi', 'high', 'highlight', ...]
|
118
124
|
trie.words 'hi' # => ['hi', 'high', 'highlight', ...]
|
119
125
|
```
|
120
126
|
|
121
127
|
To get all the words within a given string, you can use `#words_within`:
|
122
128
|
|
123
|
-
```
|
129
|
+
```ruby
|
124
130
|
trie.words_within 'ifdxawesome45someword3' # => ['if', 'aw', 'awe', ...]
|
125
131
|
trie.words_within 'tktktktk' # => []
|
126
132
|
```
|
@@ -128,7 +134,7 @@ trie.words_within 'tktktktk' # => []
|
|
128
134
|
Or, if you're just interested in knowing whether a given string contains any valid words or not, you can
|
129
135
|
use `#words_within?`:
|
130
136
|
|
131
|
-
```
|
137
|
+
```ruby
|
132
138
|
trie.words_within? 'ifdxawesome45someword3' # => true
|
133
139
|
trie.words_within? 'tktktktk' # => false
|
134
140
|
```
|
@@ -138,7 +144,7 @@ trie.words_within? 'tktktktk' # => false
|
|
138
144
|
By default, the Rambling Trie works as a standard trie. Starting from version 0.1.0, you can obtain a compressed trie
|
139
145
|
from the standard one, by using the compression feature. Just call the `#compress!` method on the trie instance:
|
140
146
|
|
141
|
-
```
|
147
|
+
```ruby
|
142
148
|
trie.compress!
|
143
149
|
```
|
144
150
|
|
@@ -151,13 +157,13 @@ non-terminal nodes).
|
|
151
157
|
|
152
158
|
If you want, you can also create a new compressed trie and leave the existing one intact. Just use `#compress` instead:
|
153
159
|
|
154
|
-
```
|
160
|
+
```ruby
|
155
161
|
compressed_trie = trie.compress
|
156
162
|
```
|
157
163
|
|
158
164
|
You can find out if a trie instance is compressed by calling the `#compressed?` method. From the `#compress` example:
|
159
165
|
|
160
|
-
```
|
166
|
+
```ruby
|
161
167
|
trie.compressed? # => false
|
162
168
|
compressed_trie.compressed? # => true
|
163
169
|
```
|
@@ -167,7 +173,7 @@ compressed_trie.compressed? # => true
|
|
167
173
|
Starting from version 0.4.2, you can use any `Enumerable` method over a trie instance, and it will iterate over each
|
168
174
|
word contained in the trie. You can now do things like:
|
169
175
|
|
170
|
-
```
|
176
|
+
```ruby
|
171
177
|
trie.each { |word| puts word }
|
172
178
|
trie.any? { |word| word.include? 'x' }
|
173
179
|
trie.all? { |word| word.include? 'x' }
|
@@ -183,14 +189,14 @@ change with little frequency.
|
|
183
189
|
|
184
190
|
To store a trie on disk, you can use `.dump` like this:
|
185
191
|
|
186
|
-
```
|
192
|
+
```ruby
|
187
193
|
Rambling::Trie.dump trie, '/path/to/file'
|
188
194
|
```
|
189
195
|
|
190
196
|
Then, when you need to use a trie next time, you don't have to create a new one with all the necessary words. Rather,
|
191
197
|
you can retrieve a previously stored one with `.load` like this:
|
192
198
|
|
193
|
-
```
|
199
|
+
```ruby
|
194
200
|
trie = Rambling::Trie.load '/path/to/file'
|
195
201
|
```
|
196
202
|
|
@@ -208,19 +214,19 @@ Currently, these formats are supported to store tries on disk:
|
|
208
214
|
Optionally, you can use a `.zip` version of the supported formats. In order to do so, you'll have to install
|
209
215
|
the [`rubyzip`][rubyzip] gem:
|
210
216
|
|
211
|
-
```
|
217
|
+
```shell
|
212
218
|
gem install rubyzip
|
213
219
|
```
|
214
220
|
|
215
221
|
Or, include it in your `Gemfile` and bundle it:
|
216
222
|
|
217
|
-
```
|
223
|
+
```ruby
|
218
224
|
gem 'rubyzip'
|
219
225
|
```
|
220
226
|
|
221
227
|
Then, you can load contents form a `.zip` file like this:
|
222
228
|
|
223
|
-
```
|
229
|
+
```ruby
|
224
230
|
require 'zip'
|
225
231
|
trie = Rambling::Trie.load '/path/to/file.zip'
|
226
232
|
```
|
@@ -271,11 +277,11 @@ The Rambling Trie has been tested with the following Ruby versions:
|
|
271
277
|
* 3.3.x
|
272
278
|
* 3.2.x
|
273
279
|
* 3.1.x
|
274
|
-
* 3.0.x
|
275
|
-
* 2.7.x
|
276
280
|
|
277
281
|
**No longer supported**:
|
278
282
|
|
283
|
+
* 3.0.x (EOL'ed)
|
284
|
+
* 2.7.x (EOL'ed)
|
279
285
|
* 2.6.x (EOL'ed)
|
280
286
|
* 2.5.x (EOL'ed)
|
281
287
|
* 2.4.x (EOL'ed)
|
@@ -310,7 +316,7 @@ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEM
|
|
310
316
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
311
317
|
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
312
318
|
|
313
|
-
[badge_fury_badge]: https://badge.fury.io/rb/rambling-trie.svg?version=2.
|
319
|
+
[badge_fury_badge]: https://badge.fury.io/rb/rambling-trie.svg?version=2.5.1
|
314
320
|
[badge_fury_link]: https://badge.fury.io/rb/rambling-trie
|
315
321
|
[chruby]: https://github.com/postmodern/chruby
|
316
322
|
[code_climate_grade_badge]: https://codeclimate.com/github/gonzedge/rambling-trie/badges/gpa.svg
|
@@ -327,17 +333,17 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
327
333
|
[github_action_codeql_badge]: https://github.com/gonzedge/rambling-trie/actions/workflows/codeql.yml/badge.svg
|
328
334
|
[github_action_codeql_link]: https://github.com/gonzedge/rambling-trie/actions/workflows/codeql.yml
|
329
335
|
[github_user_gonzedge]: https://github.com/gonzedge
|
330
|
-
[inch_ci_badge]: https://inch-ci.org/github/gonzedge/rambling-trie.svg?branch=
|
336
|
+
[inch_ci_badge]: https://inch-ci.org/github/gonzedge/rambling-trie.svg?branch=main
|
331
337
|
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
|
332
338
|
[license_link]: https://opensource.org/licenses/mit-license.php
|
333
|
-
[marshal]: https://ruby-doc.org/
|
339
|
+
[marshal]: https://ruby-doc.org/3.3.0/Marshal.html
|
334
340
|
[rambling_trie_configuration]: https://github.com/gonzedge/rambling-trie#configuration
|
335
|
-
[rambling_trie_contributing_guide]: https://github.com/gonzedge/rambling-trie/blob/
|
336
|
-
[rambling_trie_plain_text_reader]: https://github.com/gonzedge/rambling-trie/blob/
|
341
|
+
[rambling_trie_contributing_guide]: https://github.com/gonzedge/rambling-trie/blob/main/CONTRIBUTING.md
|
342
|
+
[rambling_trie_plain_text_reader]: https://github.com/gonzedge/rambling-trie/blob/main/lib/rambling/trie/readers/plain_text.rb
|
337
343
|
[rbenv]: https://github.com/sstephenson/rbenv
|
338
344
|
[rubydoc]: http://rubydoc.info/gems/rambling-trie
|
339
345
|
[rubydoc_github]: http://rubydoc.info/github/gonzedge/rambling-trie
|
340
346
|
[rubyzip]: https://github.com/rubyzip/rubyzip
|
341
347
|
[rvm]: https://rvm.io
|
342
348
|
[trie_wiki]: https://en.wikipedia.org/wiki/Trie
|
343
|
-
[yaml]: https://ruby-doc.org/
|
349
|
+
[yaml]: https://ruby-doc.org/3.3.0/stdlibs/yaml/YAML.html
|
data/Rakefile
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
+
require 'reek/rake/task'
|
4
5
|
require 'rspec/core/rake_task'
|
5
6
|
require 'rubocop/rake_task'
|
7
|
+
require 'steep/rake_task'
|
8
|
+
require 'yard'
|
6
9
|
|
7
10
|
require 'rambling-trie'
|
8
11
|
require_relative 'tasks/performance'
|
@@ -10,6 +13,9 @@ require_relative 'tasks/serialization'
|
|
10
13
|
require_relative 'tasks/ips'
|
11
14
|
|
12
15
|
RSpec::Core::RakeTask.new :spec
|
16
|
+
Reek::Rake::Task.new :reek
|
13
17
|
RuboCop::RakeTask.new :rubocop
|
18
|
+
Steep::RakeTask.new :steep
|
19
|
+
YARD::Rake::YardocTask.new :yard
|
14
20
|
|
15
21
|
task default: :spec
|
data/Steepfile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# D = Steep::Diagnostic
|
4
|
+
#
|
5
|
+
target :lib do
|
6
|
+
signature 'sig'
|
7
|
+
|
8
|
+
check 'lib'
|
9
|
+
# check 'tasks'
|
10
|
+
|
11
|
+
# check 'Gemfile'
|
12
|
+
# check 'Guardfile'
|
13
|
+
# check 'Rakefile'
|
14
|
+
# check 'Steepfile'
|
15
|
+
|
16
|
+
# library 'rubyzip'
|
17
|
+
library 'yaml'
|
18
|
+
library 'securerandom'
|
19
|
+
|
20
|
+
# configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
|
21
|
+
# configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
|
22
|
+
# configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
|
23
|
+
# configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
|
24
|
+
# configure_code_diagnostics do |hash| # You can setup everything yourself
|
25
|
+
# hash[D::Ruby::NoMethod] = :information
|
26
|
+
# end
|
27
|
+
end
|
28
|
+
|
29
|
+
# target :test do
|
30
|
+
# signature 'sig', 'sig-private'
|
31
|
+
#
|
32
|
+
# check 'test'
|
33
|
+
#
|
34
|
+
# # library 'pathname' # Standard libraries
|
35
|
+
# end
|
@@ -6,8 +6,8 @@ module Rambling
|
|
6
6
|
module Comparable
|
7
7
|
# Compares two nodes.
|
8
8
|
# @param [Nodes::Node] other the node to compare against.
|
9
|
-
# @return [Boolean]
|
10
|
-
# {Nodes::Node#children_tree #children_tree} are equal,
|
9
|
+
# @return [Boolean] `true` if the nodes' {Nodes::Node#letter #letter} and
|
10
|
+
# {Nodes::Node#children_tree #children_tree} are equal, `false` otherwise.
|
11
11
|
def == other
|
12
12
|
letter == other.letter &&
|
13
13
|
terminal? == other.terminal? &&
|
@@ -5,7 +5,7 @@ module Rambling
|
|
5
5
|
# Provides the compressible behavior for the trie data structure.
|
6
6
|
module Compressible
|
7
7
|
# Indicates if the current {Rambling::Trie::Nodes::Node Node} can be compressed or not.
|
8
|
-
# @return [Boolean]
|
8
|
+
# @return [Boolean] `true` for non-{Nodes::Node#terminal? terminal} nodes with one child, `false` otherwise.
|
9
9
|
def compressible?
|
10
10
|
!(root? || terminal?) && 1 == children_tree.size
|
11
11
|
end
|
@@ -5,11 +5,13 @@ module Rambling
|
|
5
5
|
# Responsible for the compression process of a trie data structure.
|
6
6
|
class Compressor
|
7
7
|
# Compresses a {Nodes::Node Node} from a trie data structure.
|
8
|
-
# @param [Nodes::
|
9
|
-
# @return [Nodes::Compressed] node the compressed version of the node.
|
8
|
+
# @param [Nodes::Node, nil] node the node to compress.
|
9
|
+
# @return [Nodes::Compressed, nil] node the compressed version of the node.
|
10
10
|
def compress node
|
11
|
+
return unless node
|
12
|
+
|
11
13
|
if node.compressible?
|
12
|
-
|
14
|
+
compress_only_child_and_merge node
|
13
15
|
else
|
14
16
|
compress_children_and_copy node
|
15
17
|
end
|
@@ -17,38 +19,39 @@ module Rambling
|
|
17
19
|
|
18
20
|
private
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
# Compresses a {Nodes::Node Node} with an only child from a trie data structure.
|
23
|
+
# By this point we already know the node is not nil and that it has an only child,
|
24
|
+
# so we use the type annotation because compressed_child will always have a value.
|
25
|
+
# @see Rambling::Trie::Compressible#compressible? Compressible#compressible?
|
26
|
+
# @param [Nodes::Node] node the node to compress.
|
27
|
+
# @return [Nodes::Compressed] node the compressed version of the node.
|
28
|
+
def compress_only_child_and_merge node
|
29
|
+
compressed_child = compress(node.first_child) # : Nodes::Compressed
|
30
|
+
merge node, compressed_child
|
22
31
|
end
|
23
32
|
|
24
33
|
def merge node, other
|
25
34
|
letter = node.letter.to_s << other.letter.to_s
|
26
35
|
|
27
|
-
|
36
|
+
compressed = Rambling::Trie::Nodes::Compressed.new letter.to_sym, node.parent, other.children_tree
|
37
|
+
compressed.terminal! if other.terminal?
|
38
|
+
compressed
|
28
39
|
end
|
29
40
|
|
30
41
|
def compress_children_and_copy node
|
31
|
-
|
42
|
+
children_tree = compress_children(node.children_tree)
|
43
|
+
compressed = Rambling::Trie::Nodes::Compressed.new node.letter, node.parent, children_tree
|
44
|
+
compressed.terminal! if node.terminal?
|
45
|
+
compressed
|
32
46
|
end
|
33
47
|
|
34
48
|
def compress_children tree
|
35
49
|
new_tree = {}
|
36
50
|
|
37
|
-
tree.each
|
38
|
-
compressed_child = compress child
|
39
|
-
new_tree[letter] = compressed_child
|
40
|
-
end
|
51
|
+
tree.each { |letter, child| new_tree[letter] = compress child }
|
41
52
|
|
42
53
|
new_tree
|
43
54
|
end
|
44
|
-
|
45
|
-
def new_compressed_node letter, parent, tree, terminal
|
46
|
-
node = Rambling::Trie::Nodes::Compressed.new letter, parent, tree
|
47
|
-
node.terminal! if terminal
|
48
|
-
|
49
|
-
tree.each_value { |child| child.parent = node }
|
50
|
-
node
|
51
|
-
end
|
52
55
|
end
|
53
56
|
end
|
54
57
|
end
|
@@ -4,6 +4,7 @@ module Rambling
|
|
4
4
|
module Trie
|
5
5
|
module Configuration
|
6
6
|
# Provides configurable properties for Rambling::Trie.
|
7
|
+
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
7
8
|
class Properties
|
8
9
|
# The configured {Readers Readers}.
|
9
10
|
# @return [ProviderCollection<Readers::Reader>] the mapping of configured {Readers Readers}.
|
@@ -17,12 +18,12 @@ module Rambling
|
|
17
18
|
# @return [Compressor] the configured compressor.
|
18
19
|
attr_accessor :compressor
|
19
20
|
|
20
|
-
# The configured
|
21
|
-
# @return [Proc<Nodes::Node>] the configured
|
21
|
+
# The configured `root_builder`, which returns a {Nodes::Node Node} when called.
|
22
|
+
# @return [Proc<Nodes::Node>] the configured `root_builder`.
|
22
23
|
attr_accessor :root_builder
|
23
24
|
|
24
|
-
# The configured
|
25
|
-
# @return [String] the configured
|
25
|
+
# The configured `tmp_path`, which will be used for throwaway files.
|
26
|
+
# @return [String] the configured `tmp_path`.
|
26
27
|
attr_accessor :tmp_path
|
27
28
|
|
28
29
|
# Returns a new properties instance.
|
@@ -46,8 +47,11 @@ module Rambling
|
|
46
47
|
attr_writer :readers, :serializers
|
47
48
|
|
48
49
|
def reset_readers
|
49
|
-
|
50
|
-
|
50
|
+
@readers = Rambling::Trie::Configuration::ProviderCollection.new :reader, default_reader_providers
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_reader_providers
|
54
|
+
{ txt: Rambling::Trie::Readers::PlainText.new }
|
51
55
|
end
|
52
56
|
|
53
57
|
def reset_serializers
|
@@ -17,7 +17,7 @@ module Rambling
|
|
17
17
|
# providers.
|
18
18
|
# @param [TProvider] provider the provider to use as default.
|
19
19
|
# @raise [ArgumentError] when the given provider is not in the provider collection.
|
20
|
-
# @note If no providers have been configured,
|
20
|
+
# @note If no providers have been configured, `nil` will be assigned.
|
21
21
|
# @return [TProvider, nil] the default provider to use when a provider cannot be resolved in
|
22
22
|
# {ProviderCollection#resolve #resolve}.
|
23
23
|
attr_reader :default
|
@@ -58,20 +58,25 @@ module Rambling
|
|
58
58
|
# @param [String] filepath the filepath to resolve into a provider.
|
59
59
|
# @return [TProvider, nil] the provider for the given file's extension. {#default} if not found.
|
60
60
|
def resolve filepath
|
61
|
-
|
61
|
+
extension = file_format filepath
|
62
|
+
if providers.key? extension
|
63
|
+
providers[extension]
|
64
|
+
else
|
65
|
+
default
|
66
|
+
end
|
62
67
|
end
|
63
68
|
|
64
69
|
# Resets the provider collection to the initial values.
|
65
70
|
# @return [void]
|
66
71
|
def reset
|
67
72
|
providers.clear
|
68
|
-
configured_providers.each { |
|
73
|
+
configured_providers.each { |extension, provider| self[extension] = provider }
|
69
74
|
self.default = configured_default
|
70
75
|
end
|
71
76
|
|
72
77
|
# Get provider corresponding to a given format.
|
73
78
|
# @return [Array<Symbol>] the provider corresponding to that format.
|
74
|
-
# @see https://ruby-doc.org/
|
79
|
+
# @see https://ruby-doc.org/3.3.0/Hash.html#method-i-5B-5D
|
75
80
|
# Hash#keys
|
76
81
|
def formats
|
77
82
|
providers.keys
|
@@ -80,7 +85,7 @@ module Rambling
|
|
80
85
|
# Get provider corresponding to a given format.
|
81
86
|
# @param [Symbol] format the format to search for in the collection.
|
82
87
|
# @return [TProvider] the provider corresponding to that format.
|
83
|
-
# @see https://ruby-doc.org/
|
88
|
+
# @see https://ruby-doc.org/3.3.0/Hash.html#method-i-5B-5D Hash#[]
|
84
89
|
def [] format
|
85
90
|
providers[format]
|
86
91
|
end
|
@@ -98,13 +103,13 @@ module Rambling
|
|
98
103
|
end
|
99
104
|
|
100
105
|
def file_format filepath
|
101
|
-
|
102
|
-
format.slice! 0
|
103
|
-
format.to_sym
|
106
|
+
File.extname(filepath).sub(%r{^\.}, '').to_sym
|
104
107
|
end
|
105
108
|
|
106
109
|
def contains? provider
|
107
|
-
|
110
|
+
return true if provider.nil?
|
111
|
+
|
112
|
+
providers.any? && provider_instances.include?(provider || raise)
|
108
113
|
end
|
109
114
|
|
110
115
|
alias_method :provider_instances, :values
|
@@ -1,8 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
path = File.join 'rambling', 'trie', 'configuration'
|
4
|
+
%w(properties provider_collection).each { |file| require File.join(path, file) }
|
6
5
|
|
7
6
|
module Rambling
|
8
7
|
module Trie
|