rambling-trie 2.5.1 → 2.6.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +28 -20
  4. data/lib/rambling/trie/compressor.rb +16 -4
  5. data/lib/rambling/trie/container.rb +9 -5
  6. data/lib/rambling/trie/enumerable.rb +2 -1
  7. data/lib/rambling/trie/inspectable.rb +6 -1
  8. data/lib/rambling/trie/nodes/compressed.rb +2 -2
  9. data/lib/rambling/trie/nodes/node.rb +4 -0
  10. data/lib/rambling/trie/nodes/raw.rb +8 -5
  11. data/lib/rambling/trie/serializers/zip.rb +2 -2
  12. data/lib/rambling/trie/version.rb +1 -1
  13. data/lib/rambling/trie.rb +3 -3
  14. data/rambling-trie.gemspec +1 -1
  15. data/sig/lib/nilable.rbs +3 -0
  16. data/sig/lib/rambling/trie/comparable.rbs +3 -3
  17. data/sig/lib/rambling/trie/compressible.rbs +2 -2
  18. data/sig/lib/rambling/trie/compressor.rbs +6 -6
  19. data/sig/lib/rambling/trie/configuration/properties.rbs +5 -5
  20. data/sig/lib/rambling/trie/configuration/provider_collection.rbs +0 -4
  21. data/sig/lib/rambling/trie/container.rbs +17 -17
  22. data/sig/lib/rambling/trie/enumerable.rbs +3 -3
  23. data/sig/lib/rambling/trie/inspectable.rbs +7 -2
  24. data/sig/lib/rambling/trie/nodes/compressed.rbs +4 -4
  25. data/sig/lib/rambling/trie/nodes/missing.rbs +2 -2
  26. data/sig/lib/rambling/trie/nodes/node.rbs +20 -19
  27. data/sig/lib/rambling/trie/nodes/raw.rbs +5 -5
  28. data/sig/lib/rambling/trie/readers/plain_text.rbs +1 -1
  29. data/sig/lib/rambling/trie/serializers/marshal.rbs +1 -1
  30. data/sig/lib/rambling/trie/serializers/yaml.rbs +1 -1
  31. data/sig/lib/rambling/trie/serializers/zip.rbs +5 -5
  32. data/sig/lib/rambling/trie/stringifyable.rbs +3 -3
  33. data/sig/lib/rambling/trie.rbs +8 -10
  34. data/sig/lib/zip/entry.rbs +2 -2
  35. data/sig/lib/zip/file.rbs +2 -4
  36. metadata +6 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c38f152f6ffdb5b7c3f5abde873ae3024651a52a7697fa4e706d01e28fe504e
4
- data.tar.gz: 8cdec337b99995019a24d702b48dce2ee3e9a9e6acde298cd5cfef8086e93bc9
3
+ metadata.gz: 52fe8e610cf15d433a18cbb24cdd4b72c48a4ab50398868ab68cce58ea0a8de6
4
+ data.tar.gz: a106639989c7ad33230c252d470a9c7924fd65204ab633743bd813d4f69fa4d4
5
5
  SHA512:
6
- metadata.gz: 6bbadda2f93e7efdae19f0db8749e304be56b288d62095a269904c4d6e3b6e2f7723acba618fd4e8e8de416108ca9e6249c7a6c9ce5a70e70036e6ad287cb7e2
7
- data.tar.gz: b60a49628ba61bca14d5a92573df83203feb0346d306adbc628ab7dfad54da82574902ee1f4985a365582a6c5a285b788a108ee7e7d2c22b0ce3f06dc5eccf78
6
+ metadata.gz: 6d4659cf7e712e4fbed4e6054d6f27f7db0ecbf4dca13fcad6cab34c3050b78cb63cee7993ccda2146868b8d7203932bea08667bb510d0afdcada8cb403c3418
7
+ data.tar.gz: a36621b0ee84dbb8905ca8af25b8fc1b2b08a23ce171fb83c3ec632f39ffc1e7108828330eb93c4285948e5c32a1a6c6d116ad74d9da5a28aa9bd428110dafe5
data/Gemfile CHANGED
@@ -18,6 +18,7 @@ group :test do
18
18
  end
19
19
 
20
20
  group :local do
21
+ gem 'benchmark', require: false
21
22
  gem 'benchmark-ips', require: false
22
23
  gem 'flamegraph', require: false
23
24
  gem 'flog', require: false
@@ -26,6 +27,7 @@ group :local do
26
27
  gem 'guard-rspec', require: false
27
28
  gem 'guard-rubocop', require: false
28
29
  gem 'guard-yard', require: false
30
+ gem 'irb', require: false
29
31
  gem 'mdl', require: false
30
32
  gem 'memory_profiler', require: false
31
33
  gem 'pry', require: false
data/README.md CHANGED
@@ -9,9 +9,6 @@
9
9
  [![Documentation Status][inch_ci_badge]][rubydoc]
10
10
  [![CodeQL Status][github_action_codeql_badge]][github_action_codeql_link]
11
11
 
12
- [![Code Climate Grade][code_climate_grade_badge]][code_climate_link]
13
- [![Code Climate Issue Count][code_climate_issues_badge]][code_climate_link]
14
-
15
12
  The Rambling Trie is a Ruby implementation of the [trie data structure][trie_wiki], which includes compression abilities
16
13
  and is designed to be very fast to traverse.
17
14
 
@@ -21,10 +18,10 @@ and is designed to be very fast to traverse.
21
18
 
22
19
  You will need:
23
20
 
24
- * Ruby 3.1.0 or up
21
+ * Ruby 3.2.0 or up
25
22
  * RubyGems
26
23
 
27
- See [RVM][rvm], [rbenv][rbenv] or [chruby][chruby] for more information on how to manage Ruby versions.
24
+ See [asdf][asdf], [RVM][rvm], [rbenv][rbenv] or [chruby][chruby] for more information on how to manage Ruby versions.
28
25
 
29
26
  ### Installation
30
27
 
@@ -77,9 +74,8 @@ trie
77
74
  ```
78
75
 
79
76
  If you want to use a custom file format, you will need to provide a custom `Reader` that defines an `#each_word` method
80
- that yields each word contained in the file. Look at the [`PlainText` reader][rambling_trie_plain_text_reader] class for
81
- an example, and at the [Configuration section][rambling_trie_configuration] to see how to add your own custom file
82
- readers.
77
+ that yields each word contained in the file. Look at the [`PlainText` reader](./lib/rambling/trie/readers/plain_text.rb)
78
+ class for an example, and at the [Configuration section](#configuration) to see how to add your own custom file readers.
83
79
 
84
80
  ### Operations
85
81
 
@@ -182,7 +178,7 @@ trie.all? { |word| word.include? 'x' }
182
178
 
183
179
  ### Serialization
184
180
 
185
- Starting from version 1.0.0, you can store a full trie instance on disk and retrieve/use it later on. Loading a trie
181
+ Starting from version `1.0.0`, you can store a full trie instance on disk and retrieve/use it later on. Loading a trie
186
182
  from disk takes less time, less cpu and less memory than loading every word into the trie every time. This is
187
183
  particularly useful for production applications, when you have word lists that you know are going to be static, or that
188
184
  change with little frequency.
@@ -206,22 +202,29 @@ Currently, these formats are supported to store tries on disk:
206
202
 
207
203
  * Ruby's [binary (Marshal)][marshal] format
208
204
  * [YAML][yaml]
205
+ * Zip version of any other format ([optional `rubyzip` dependency](#optional-rubyzip-dependency))
206
+
207
+ > When dumping into or loading from disk, the format is determined automatically based on the file extension, so `.yml`
208
+ > or `.yaml` files will be handled through `YAML` and `.marshal` files through `Marshal`.
209
+
210
+ ##### Optional `rubyzip` dependency
209
211
 
210
- > When dumping into or loading from disk, the format is determined
211
- > automatically based on the file extension, so `.yml` or `.yaml` files will be
212
- > handled through `YAML` and `.marshal` files through `Marshal`.
212
+ Compressed versions of all other [supported formats](#supported-formats) are available via the [`rubyzip`][rubyzip] gem.
213
+ This is an optional dependency.
213
214
 
214
- Optionally, you can use a `.zip` version of the supported formats. In order to do so, you'll have to install
215
- the [`rubyzip`][rubyzip] gem:
215
+ > ⚠️ Rambling Trie `2.6.0` and above support `rubyzip` `3.x` only.
216
+ > For `rubyzip` `2.x` support, use Rambling Trie `2.5.1` and below.
216
217
 
217
218
  ```shell
218
219
  gem install rubyzip
220
+ # or gem install rubyzip --version '<3` for 2.x
219
221
  ```
220
222
 
221
223
  Or, include it in your `Gemfile` and bundle it:
222
224
 
223
225
  ```ruby
224
226
  gem 'rubyzip'
227
+ # or gem 'rubyzip', '<3' for 2.x
225
228
  ```
226
229
 
227
230
  Then, you can load contents form a `.zip` file like this:
@@ -274,12 +277,14 @@ want edge documentation, you can go the [GitHub project RubyDoc.info page][rubyd
274
277
 
275
278
  The Rambling Trie has been tested with the following Ruby versions:
276
279
 
280
+ * 4.0.x
281
+ * 3.4.x
277
282
  * 3.3.x
278
283
  * 3.2.x
279
- * 3.1.x
280
284
 
281
285
  **No longer supported**:
282
286
 
287
+ * 3.1.x (EOL'ed)
283
288
  * 3.0.x (EOL'ed)
284
289
  * 2.7.x (EOL'ed)
285
290
  * 2.6.x (EOL'ed)
@@ -292,9 +297,14 @@ The Rambling Trie has been tested with the following Ruby versions:
292
297
  * 1.9.x (EOL'ed)
293
298
  * 1.8.x (EOL'ed)
294
299
 
300
+ ## Compatible RBS and Steep versions
301
+
302
+ Type signatures for `Rambling::Trie` are included in the [`sig` directory](./sig)! The current version (`2.6.0`) was
303
+ checked with RBS `3.10.4` and Steep `1.10.0`.
304
+
295
305
  ## Contributing to Rambling Trie
296
306
 
297
- Take a look at the [contributing guide][rambling_trie_contributing_guide] to get started, or fire a question
307
+ Take a look at the [contributing guide](./CONTRIBUTING.md) to get started, or fire a question
298
308
  to [@gonzedge][github_user_gonzedge].
299
309
 
300
310
  ## License and copyright
@@ -316,7 +326,8 @@ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEM
316
326
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
317
327
  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
318
328
 
319
- [badge_fury_badge]: https://badge.fury.io/rb/rambling-trie.svg?version=2.5.1
329
+ [asdf]: https://asdf-vm.com/
330
+ [badge_fury_badge]: https://badge.fury.io/rb/rambling-trie.svg?version=2.6.0
320
331
  [badge_fury_link]: https://badge.fury.io/rb/rambling-trie
321
332
  [chruby]: https://github.com/postmodern/chruby
322
333
  [code_climate_grade_badge]: https://codeclimate.com/github/gonzedge/rambling-trie/badges/gpa.svg
@@ -337,9 +348,6 @@ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
337
348
  [license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
338
349
  [license_link]: https://opensource.org/licenses/mit-license.php
339
350
  [marshal]: https://ruby-doc.org/3.3.0/Marshal.html
340
- [rambling_trie_configuration]: https://github.com/gonzedge/rambling-trie#configuration
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
343
351
  [rbenv]: https://github.com/sstephenson/rbenv
344
352
  [rubydoc]: http://rubydoc.info/gems/rambling-trie
345
353
  [rubydoc_github]: http://rubydoc.info/github/gonzedge/rambling-trie
@@ -26,7 +26,7 @@ module Rambling
26
26
  # @param [Nodes::Node] node the node to compress.
27
27
  # @return [Nodes::Compressed] node the compressed version of the node.
28
28
  def compress_only_child_and_merge node
29
- compressed_child = compress(node.first_child) # : Nodes::Compressed
29
+ compressed_child = compress(node.first_child) || raise(InvalidOperation, 'got nil while compressing only child')
30
30
  merge node, compressed_child
31
31
  end
32
32
 
@@ -34,21 +34,33 @@ module Rambling
34
34
  letter = node.letter.to_s << other.letter.to_s
35
35
 
36
36
  compressed = Rambling::Trie::Nodes::Compressed.new letter.to_sym, node.parent, other.children_tree
37
- compressed.terminal! if other.terminal?
37
+ if other.terminal?
38
+ compressed.terminal!
39
+ value = other.value
40
+ compressed.value = value if value
41
+ end
38
42
  compressed
39
43
  end
40
44
 
41
45
  def compress_children_and_copy node
42
46
  children_tree = compress_children(node.children_tree)
43
47
  compressed = Rambling::Trie::Nodes::Compressed.new node.letter, node.parent, children_tree
44
- compressed.terminal! if node.terminal?
48
+ if node.terminal?
49
+ compressed.terminal!
50
+ value = node.value
51
+ compressed.value = value if value
52
+ end
45
53
  compressed
46
54
  end
47
55
 
48
56
  def compress_children tree
57
+ # @type var new_tree: Hash[Symbol, Nodes::Node]
49
58
  new_tree = {}
50
59
 
51
- tree.each { |letter, child| new_tree[letter] = compress child }
60
+ tree.each do |letter, child|
61
+ compressed_child = compress(child) || raise(InvalidOperation, "got nil while compressing #{letter}")
62
+ new_tree[letter] = compressed_child
63
+ end
52
64
 
53
65
  new_tree
54
66
  end
@@ -27,8 +27,8 @@ module Rambling
27
27
  # @raise [InvalidOperation] if the trie is already compressed.
28
28
  # @see Nodes::Raw#add
29
29
  # @see Nodes::Compressed#add
30
- def add word
31
- root.add reversed_char_symbols word
30
+ def add word, value = nil
31
+ root.add reversed_char_symbols(word), value
32
32
  end
33
33
 
34
34
  # Adds all provided words to the trie.
@@ -37,8 +37,12 @@ module Rambling
37
37
  # @raise [InvalidOperation] if the trie is already compressed.
38
38
  # @see Nodes::Raw#add
39
39
  # @see Nodes::Compressed#add
40
- def concat words
41
- words.map { |word| add word }
40
+ def concat words, values = nil
41
+ if values
42
+ words.each_with_index.map { |word, index| add(word, values[index]) }
43
+ else
44
+ words.map { |word| add word }
45
+ end
42
46
  end
43
47
 
44
48
  # Compresses the existing trie using redundant node elimination.
@@ -209,7 +213,7 @@ module Rambling
209
213
  end
210
214
 
211
215
  def compress_root
212
- compressor.compress root # : Nodes::Compressed
216
+ compressor.compress(root) || raise
213
217
  end
214
218
 
215
219
  def reversed_char_symbols word
@@ -7,7 +7,8 @@ module Rambling
7
7
  include ::Enumerable
8
8
 
9
9
  # Empty enumerator constant for early each exits.
10
- EMPTY_ENUMERATOR = [].to_enum :each
10
+ EMPTY_ENUMERATOR = [] # : Array[String]
11
+ .to_enum :each
11
12
 
12
13
  # Returns number of words contained in the trie
13
14
  # @see https://ruby-doc.org/3.3.0/Enumerable.html#method-i-count Enumerable#count
@@ -18,15 +18,20 @@ module Rambling
18
18
  def attributes
19
19
  [
20
20
  letter_inspect,
21
+ value_inspect,
21
22
  terminal_inspect,
22
23
  children_inspect,
23
- ].join ', '
24
+ ].compact.join ', '
24
25
  end
25
26
 
26
27
  def letter_inspect
27
28
  "letter: #{letter.inspect}"
28
29
  end
29
30
 
31
+ def value_inspect
32
+ value && "value: #{value.inspect}"
33
+ end
34
+
30
35
  def terminal_inspect
31
36
  "terminal: #{terminal.inspect}"
32
37
  end
@@ -3,7 +3,7 @@
3
3
  module Rambling
4
4
  module Trie
5
5
  module Nodes
6
- # A representation of a node in an compressed trie data structure.
6
+ # A representation of a node in a compressed trie data structure.
7
7
  # :reek:RepeatedConditional { max_ifs: 4 }
8
8
  class Compressed < Rambling::Trie::Nodes::Node
9
9
  # Creates a new compressed node.
@@ -22,7 +22,7 @@ module Rambling
22
22
  # @param [String] _ the word to add to the trie.
23
23
  # @raise [InvalidOperation] if the trie is already compressed.
24
24
  # @return [void]
25
- def add _
25
+ def add _, _ = nil
26
26
  raise Rambling::Trie::InvalidOperation, 'Cannot add word to compressed trie'
27
27
  end
28
28
 
@@ -31,6 +31,10 @@ module Rambling
31
31
  # @return [Node, nil] the parent of the current node.
32
32
  attr_accessor :parent
33
33
 
34
+ # Arbitrary value stored in this node
35
+ # @return [TValue, nil] the parent of the current node.
36
+ attr_accessor :value
37
+
34
38
  # Creates a new node.
35
39
  # @param [Symbol, nil] letter the Node's letter value.
36
40
  # @param [Node, nil] parent the parent of the current node.
@@ -10,12 +10,15 @@ module Rambling
10
10
  # @param [Array<Symbol>] reversed_chars the char array to add to the trie, in reverse order.
11
11
  # @return [Node] the added/modified node based on the word added.
12
12
  # @note This method clears the contents of the chars variable.
13
- def add reversed_chars
13
+ def add reversed_chars, value = nil
14
14
  if reversed_chars.empty?
15
- terminal! unless root?
15
+ unless root?
16
+ self.value = value
17
+ terminal!
18
+ end
16
19
  self
17
20
  else
18
- add_to_children_tree reversed_chars
21
+ add_to_children_tree reversed_chars, value
19
22
  end
20
23
  end
21
24
 
@@ -27,10 +30,10 @@ module Rambling
27
30
 
28
31
  private
29
32
 
30
- def add_to_children_tree chars
33
+ def add_to_children_tree chars, value = nil
31
34
  letter = chars.pop || raise
32
35
  child = children_tree[letter] || new_node(letter)
33
- child.add chars
36
+ child.add chars, value
34
37
  child
35
38
  end
36
39
 
@@ -30,7 +30,7 @@ module Rambling
30
30
 
31
31
  entry_name = entry.name
32
32
  entry_path = path entry_name
33
- entry.extract entry_path
33
+ entry.extract ::File.basename(entry_path), destination_directory: tmp_path
34
34
 
35
35
  serializer = serializers.resolve entry_name
36
36
  raise unless serializer
@@ -48,7 +48,7 @@ module Rambling
48
48
  def dump contents, filepath
49
49
  require 'zip'
50
50
 
51
- ::Zip::File.open filepath, ::Zip::File::CREATE do |zip|
51
+ ::Zip::File.open filepath, create: true do |zip|
52
52
  filename = ::File.basename filepath, '.zip'
53
53
 
54
54
  entry_path = path filename
@@ -3,6 +3,6 @@
3
3
  module Rambling
4
4
  module Trie
5
5
  # Current version of the rambling-trie.
6
- VERSION = '2.5.1'
6
+ VERSION = '2.6.0'
7
7
  end
8
8
  end
data/lib/rambling/trie.rb CHANGED
@@ -28,7 +28,7 @@ module Rambling
28
28
  (reader || raise).each_word(filepath) { |word| container << word }
29
29
  end
30
30
 
31
- yield container if block_given?
31
+ yield container if block_given? # steep:ignore
32
32
  end
33
33
  end
34
34
 
@@ -37,7 +37,7 @@ module Rambling
37
37
  # Available formats are `yml`, `marshal`, and `zip` versions of all the
38
38
  # previous formats. You can also define your own.
39
39
  # @param [String] filepath the file to load the words from.
40
- # @param [Serializer, nil] serializer the object responsible of loading the trie from disk.
40
+ # @param [Serializer, nil] serializer the object responsible for loading the trie from disk.
41
41
  # @return [Container] the trie just loaded.
42
42
  # @yield [Container] the trie just loaded.
43
43
  # @see Rambling::Trie::Serializers Serializers.
@@ -47,7 +47,7 @@ module Rambling
47
47
  serializer ||= serializers.resolve filepath
48
48
  root = (serializer || raise).load filepath
49
49
  Rambling::Trie::Container.new root, compressor do |container|
50
- yield container if block_given?
50
+ yield container if block_given? # steep:ignore
51
51
  end
52
52
  end
53
53
 
@@ -31,5 +31,5 @@ Gem::Specification.new do |gem|
31
31
  gem.license = 'MIT'
32
32
  gem.version = Rambling::Trie::VERSION
33
33
  gem.platform = Gem::Platform::RUBY
34
- gem.required_ruby_version = '>= 3.1', '< 4'
34
+ gem.required_ruby_version = '>= 3.2', '< 5'
35
35
  end
@@ -0,0 +1,3 @@
1
+ interface _Nilable
2
+ def nil?: -> bool
3
+ end
@@ -1,7 +1,7 @@
1
1
  module Rambling
2
2
  module Trie
3
- module Comparable
4
- def ==: (Nodes::Node) -> bool
3
+ module Comparable[TValue < _Inspect]
4
+ def ==: (Nodes::Node[TValue]) -> bool
5
5
 
6
6
  private
7
7
 
@@ -11,7 +11,7 @@ module Rambling
11
11
 
12
12
  def terminal?: -> bool
13
13
 
14
- def children_tree: -> Hash[Symbol, Nodes::Node]
14
+ def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]
15
15
  end
16
16
  end
17
17
  end
@@ -1,6 +1,6 @@
1
1
  module Rambling
2
2
  module Trie
3
- module Compressible
3
+ module Compressible[TValue < _Inspect]
4
4
  def compressible?: -> bool
5
5
 
6
6
  private
@@ -11,7 +11,7 @@ module Rambling
11
11
 
12
12
  def terminal?: -> bool
13
13
 
14
- def children_tree: -> Hash[Symbol, Nodes::Node]
14
+ def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]
15
15
  end
16
16
  end
17
17
  end
@@ -1,17 +1,17 @@
1
1
  module Rambling
2
2
  module Trie
3
- class Compressor
4
- def compress: (Nodes::Node?) -> Nodes::Compressed?
3
+ class Compressor[TValue < _Inspect]
4
+ def compress: (Nodes::Node[TValue]?) -> Nodes::Compressed[TValue]?
5
5
 
6
6
  private
7
7
 
8
- def compress_only_child_and_merge: (Nodes::Node) -> Nodes::Compressed
8
+ def compress_only_child_and_merge: (Nodes::Node[TValue]) -> Nodes::Compressed[TValue]
9
9
 
10
- def merge: (Nodes::Node, Nodes::Node) -> Nodes::Compressed
10
+ def merge: (Nodes::Node[TValue], Nodes::Node[TValue]) -> Nodes::Compressed[TValue]
11
11
 
12
- def compress_children_and_copy: (Nodes::Node) -> Nodes::Compressed
12
+ def compress_children_and_copy: (Nodes::Node[TValue]) -> Nodes::Compressed[TValue]
13
13
 
14
- def compress_children: (Hash[Symbol, Nodes::Node]) -> Hash[Symbol, Nodes::Node]
14
+ def compress_children: (Hash[Symbol, Nodes::Node[TValue]]) -> Hash[Symbol, Nodes::Node[TValue]]
15
15
  end
16
16
  end
17
17
  end
@@ -1,11 +1,11 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Configuration
4
- class Properties
4
+ class Properties[TValue < _Inspect]
5
5
  attr_reader readers: ProviderCollection[Readers::Reader]
6
- attr_reader serializers: ProviderCollection[Serializers::Serializer[Nodes::Node]]
7
- attr_accessor compressor: Compressor
8
- attr_accessor root_builder: ^() -> Nodes::Node
6
+ attr_reader serializers: ProviderCollection[Serializers::Serializer[Nodes::Node[TValue]]]
7
+ attr_accessor compressor: Compressor[TValue]
8
+ attr_accessor root_builder: ^() -> Nodes::Node[TValue]
9
9
  attr_accessor tmp_path: String
10
10
 
11
11
  def initialize: -> void
@@ -15,7 +15,7 @@ module Rambling
15
15
  private
16
16
 
17
17
  attr_writer readers: ProviderCollection[Readers::Reader]
18
- attr_writer serializers: ProviderCollection[Serializers::Serializer[Nodes::Node]]
18
+ attr_writer serializers: ProviderCollection[Serializers::Serializer[Nodes::Node[TValue]]]
19
19
 
20
20
  def reset_readers: -> void
21
21
 
@@ -2,10 +2,6 @@ module Rambling
2
2
  module Trie
3
3
  module Configuration
4
4
  class ProviderCollection[TProvider < _Nilable]
5
- interface _Nilable
6
- def nil?: -> bool
7
- end
8
-
9
5
  @providers: Hash[Symbol, TProvider]
10
6
 
11
7
  attr_reader name: Symbol
@@ -1,27 +1,27 @@
1
1
  module Rambling
2
2
  module Trie
3
- class Container
3
+ class Container[TValue < _Inspect]
4
4
  include ::Enumerable[String]
5
5
 
6
- @compressor: Compressor
6
+ @compressor: Compressor[TValue]
7
7
 
8
- attr_reader root: Nodes::Node
8
+ attr_reader root: Nodes::Node[TValue]
9
9
 
10
- def initialize: (Nodes::Node, Compressor) ?{ (Container) -> void } -> void
10
+ def initialize: (Nodes::Node[TValue], Compressor[TValue]) ?{ (Container[TValue]) -> void } -> void
11
11
 
12
- def add: (String) -> Nodes::Node
12
+ def add: (String, ?TValue?) -> Nodes::Node[TValue]
13
13
 
14
- def concat: (Array[String]) -> Array[Nodes::Node]
14
+ def concat: (Array[String], ?Array[TValue?]?) -> Array[Nodes::Node[TValue]]
15
15
 
16
- def compress!: -> Container
16
+ def compress!: -> Container[TValue]
17
17
 
18
- def compress: -> Container
18
+ def compress: -> Container[TValue]
19
19
 
20
- def each: { (String) -> void } -> (Enumerator[String, void] | Enumerable)
20
+ def each: { (String) -> void } -> (Enumerator[String, void] | Enumerable[TValue])
21
21
 
22
22
  def partial_word?: (String) -> bool
23
23
 
24
- def push: (*String) -> Array[Nodes::Node]
24
+ def push: (*String) -> Array[Nodes::Node[TValue]]
25
25
 
26
26
  def word?: (String) -> bool
27
27
 
@@ -31,13 +31,13 @@ module Rambling
31
31
 
32
32
  def words_within?: (String) -> bool
33
33
 
34
- def ==: (Container) -> bool
34
+ def ==: (Container[TValue]) -> bool
35
35
 
36
- def []: (Symbol) -> Nodes::Node
36
+ def []: (Symbol) -> Nodes::Node[TValue]?
37
37
 
38
- def children: -> Array[Nodes::Node]
38
+ def children: -> Array[Nodes::Node[TValue]]
39
39
 
40
- def children_tree: -> Hash[Symbol, Nodes::Node]
40
+ def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]
41
41
 
42
42
  def compressed?: -> bool
43
43
 
@@ -56,12 +56,12 @@ module Rambling
56
56
 
57
57
  private
58
58
 
59
- attr_reader compressor: Compressor
60
- attr_writer root: Nodes::Node
59
+ attr_reader compressor: Compressor[TValue]
60
+ attr_writer root: Nodes::Node[TValue]
61
61
 
62
62
  def words_within_root: (String) ?{ (String) -> void } -> Enumerator[String, void]
63
63
 
64
- def compress_root: -> Nodes::Compressed
64
+ def compress_root: -> Nodes::Compressed[TValue]
65
65
 
66
66
  def reversed_char_symbols: (String) -> Array[Symbol]
67
67
  end
@@ -1,13 +1,13 @@
1
1
  module Rambling
2
2
  module Trie
3
- module Enumerable
3
+ module Enumerable[TValue < _Inspect]
4
4
  include ::Enumerable[String]
5
5
 
6
6
  EMPTY_ENUMERATOR: Enumerator[String, void]
7
7
 
8
8
  alias size count
9
9
 
10
- def each: { (String) -> void } -> (Enumerator[String, void] | Enumerable)
10
+ def each: { (String) -> void } -> (Enumerator[String, void] | Enumerable[TValue])
11
11
 
12
12
  private
13
13
 
@@ -17,7 +17,7 @@ module Rambling
17
17
 
18
18
  def terminal?: -> bool
19
19
 
20
- def children_tree: -> Hash[Symbol, Nodes::Node]
20
+ def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]
21
21
  end
22
22
  end
23
23
  end
@@ -1,6 +1,7 @@
1
1
  module Rambling
2
2
  module Trie
3
- module Inspectable
3
+ module Inspectable[TValue < _Inspect]
4
+
4
5
  def inspect: -> String
5
6
 
6
7
  private
@@ -11,6 +12,8 @@ module Rambling
11
12
 
12
13
  def letter_inspect: -> String
13
14
 
15
+ def value_inspect: -> String?
16
+
14
17
  def terminal_inspect: -> String
15
18
 
16
19
  def children_inspect: -> String
@@ -19,9 +22,11 @@ module Rambling
19
22
 
20
23
  def letter: -> Symbol
21
24
 
25
+ def value: -> TValue
26
+
22
27
  def terminal: -> bool?
23
28
 
24
- def children_tree: -> Hash[Symbol, Nodes::Node]
29
+ def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]
25
30
  end
26
31
  end
27
32
  end
@@ -1,10 +1,10 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Nodes
4
- class Compressed < Node
5
- def initialize: (?Symbol?, ?Node?, ?Hash[Symbol, Node]) -> void
4
+ class Compressed[TValue < _Inspect] < Node[TValue]
5
+ def initialize: (?Symbol?, ?Node[TValue]?, ?Hash[Symbol, Node[TValue]]) -> void
6
6
 
7
- def add: (Array[Symbol]) -> Node
7
+ def add: (Array[Symbol], ?TValue) -> Node[TValue]
8
8
 
9
9
  def compressed?: -> bool
10
10
 
@@ -18,7 +18,7 @@ module Rambling
18
18
 
19
19
  def word_chars?: (Array[String]) -> bool
20
20
 
21
- def closest_node: (Array[String]) -> Node
21
+ def closest_node: (Array[String]) -> Node[TValue]
22
22
  end
23
23
  end
24
24
  end
@@ -1,9 +1,9 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Nodes
4
- class Missing < Node
4
+ class Missing[TValue < _Inspect] < Node[TValue]
5
5
  def initialize: -> void
6
6
  end
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -1,34 +1,35 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Nodes
4
- class Node
5
- include Compressible
6
- include Enumerable
7
- include Comparable
8
- include Stringifyable
9
- include Inspectable
4
+ class Node[TValue < _Inspect]
5
+ include Compressible[TValue]
6
+ include Enumerable[TValue]
7
+ include Comparable[TValue]
8
+ include Stringifyable[TValue]
9
+ include Inspectable[TValue]
10
10
 
11
11
  attr_reader letter: Symbol?
12
- attr_accessor children_tree: Hash[Symbol, Node]
13
- attr_accessor parent: Node?
12
+ attr_accessor children_tree: Hash[Symbol, Node[TValue]]
13
+ attr_accessor parent: Node[TValue]?
14
+ attr_accessor value: TValue?
14
15
 
15
- def initialize: (?Symbol?, ?Node?, ?Hash[Symbol, Node]) -> void
16
+ def initialize: (?Symbol?, ?Node[TValue]?, ?Hash[Symbol, Node[TValue]]) -> void
16
17
 
17
- def add: (Array[Symbol]) -> Node
18
+ def add: (Array[Symbol], ?TValue?) -> Node[TValue]
18
19
 
19
- def children: -> Array[Node]
20
+ def children: -> Array[Node[TValue]]
20
21
 
21
- def first_child: -> Node?
22
+ def first_child: -> Node[TValue]?
22
23
 
23
24
  def match_prefix: (Array[String]) { (String) -> void } -> Enumerator[String, void]
24
25
 
25
26
  def root?: -> bool
26
27
 
27
- def scan: (Array[String]) -> Node
28
+ def scan: (Array[String]) -> Node[TValue]
28
29
 
29
30
  def terminal?: -> bool
30
31
 
31
- def terminal!: -> Node
32
+ def terminal!: -> Node[TValue]
32
33
 
33
34
  def letter=: (String | Symbol?) -> Symbol?
34
35
 
@@ -38,13 +39,13 @@ module Rambling
38
39
 
39
40
  def word?: (Array[String]) -> bool
40
41
 
41
- def []: (Symbol) -> Node
42
+ def []: (Symbol) -> Node[TValue]?
42
43
 
43
- def []=: (Symbol, Node) -> Node
44
+ def []=: (Symbol, Node[TValue]) -> Node[TValue]
44
45
 
45
46
  def key?: (Symbol) -> bool
46
47
 
47
- def delete: (Symbol) -> Node?
48
+ def delete: (Symbol) -> Node[TValue]?
48
49
 
49
50
  alias has_key? key?
50
51
 
@@ -52,7 +53,7 @@ module Rambling
52
53
 
53
54
  attr_accessor terminal: bool?
54
55
 
55
- def missing: -> Node
56
+ def missing: -> Node[TValue]
56
57
 
57
58
  # abstract methods
58
59
 
@@ -62,7 +63,7 @@ module Rambling
62
63
 
63
64
  def word_chars?: (Array[String]) -> bool
64
65
 
65
- def closest_node: (Array[String]) -> Node
66
+ def closest_node: (Array[String]) -> Node[TValue]
66
67
  end
67
68
  end
68
69
  end
@@ -1,16 +1,16 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Nodes
4
- class Raw < Node
5
- def add: (Array[Symbol]) -> Node
4
+ class Raw[TValue < _Inspect] < Node[TValue]
5
+ def add: (Array[Symbol], ?TValue?) -> Node[TValue]
6
6
 
7
7
  def compressed?: -> bool
8
8
 
9
9
  private
10
10
 
11
- def add_to_children_tree: (Array[Symbol]) -> Node
11
+ def add_to_children_tree: (Array[Symbol], ?TValue?) -> Node[TValue]
12
12
 
13
- def new_node: (Symbol) -> Node
13
+ def new_node: (Symbol) -> Node[TValue]
14
14
 
15
15
  # overrides
16
16
 
@@ -20,7 +20,7 @@ module Rambling
20
20
 
21
21
  def word_chars?: (Array[String]) -> bool
22
22
 
23
- def closest_node: (Array[String]) -> Node
23
+ def closest_node: (Array[String]) -> Node[TValue]
24
24
  end
25
25
  end
26
26
  end
@@ -6,4 +6,4 @@ module Rambling
6
6
  end
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -1,7 +1,7 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Serializers
4
- class Marshal < Serializer[Nodes::Node]
4
+ class Marshal[TValue < _Inspect] < Serializer[Nodes::Node[TValue]]
5
5
  @serializer: Serializer[String]
6
6
 
7
7
  private
@@ -1,7 +1,7 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Serializers
4
- class Yaml < Serializer[Nodes::Node]
4
+ class Yaml[TValue < _Inspect] < Serializer[Nodes::Node[TValue]]
5
5
  @serializer: Serializer[String]
6
6
 
7
7
  private
@@ -1,16 +1,16 @@
1
1
  module Rambling
2
2
  module Trie
3
3
  module Serializers
4
- class Zip < Serializer[Nodes::Node]
5
- @properties: Configuration::Properties
4
+ class Zip[TValue < _Inspect] < Serializer[Nodes::Node[TValue]]
5
+ @properties: Configuration::Properties[TValue]
6
6
 
7
- def initialize: (Configuration::Properties) -> void
7
+ def initialize: (Configuration::Properties[TValue]) -> void
8
8
 
9
9
  private
10
10
 
11
- attr_reader properties: Configuration::Properties
11
+ attr_reader properties: Configuration::Properties[TValue]
12
12
 
13
- def serializers: -> Configuration::ProviderCollection[Serializer[Nodes::Node]]
13
+ def serializers: -> Configuration::ProviderCollection[Serializer[Nodes::Node[TValue]]]
14
14
 
15
15
  def tmp_path: -> String
16
16
 
@@ -1,6 +1,6 @@
1
1
  module Rambling
2
2
  module Trie
3
- module Stringifyable
3
+ module Stringifyable[TValue < _Inspect]
4
4
  def as_word: -> String
5
5
 
6
6
  def to_s: -> String
@@ -13,9 +13,9 @@ module Rambling
13
13
 
14
14
  def terminal?: -> bool
15
15
 
16
- def parent: -> Nodes::Node?
16
+ def parent: -> Nodes::Node[TValue]?
17
17
 
18
- def children_tree: -> Hash[Symbol, Nodes::Node]
18
+ def children_tree: -> Hash[Symbol, Nodes::Node[TValue]]
19
19
  end
20
20
  end
21
21
  end
@@ -2,26 +2,24 @@ module Rambling
2
2
  module Trie
3
3
  VERSION: String
4
4
 
5
- @properties: Configuration::Properties
5
+ def self.create: [TValue < _Inspect] (?String?, ?Readers::Reader?) ?{ (Container[TValue]) -> void } -> Container[TValue]
6
6
 
7
- def self.create: (?String?, ?Readers::Reader?) ?{ (Container) -> void } -> Container
7
+ def self.load: [TValue < _Inspect] (String, ?Serializers::Serializer[Nodes::Node[TValue]]?) ?{ (Container[TValue]) -> void } -> Container[TValue]
8
8
 
9
- def self.load: (String, ?Serializers::Serializer[Nodes::Node]?) ?{ (Container) -> void } -> Container
9
+ def self.dump: [TValue < _Inspect] (Container[TValue], String, ?Serializers::Serializer[Nodes::Node[TValue]]?) -> void
10
10
 
11
- def self.dump: (Container, String, ?Serializers::Serializer[Nodes::Node]?) -> void
12
-
13
- def self.config: ?{ (Configuration::Properties) -> void } -> Configuration::Properties
11
+ def self.config: [TValue < _Inspect] ?{ (Configuration::Properties[TValue]) -> void } -> Configuration::Properties[TValue]
14
12
 
15
13
  private
16
14
 
17
- def self.properties: -> Configuration::Properties
15
+ def self.properties: [TValue < _Inspect] -> Configuration::Properties[TValue]
18
16
 
19
17
  def self.readers: -> Configuration::ProviderCollection[Readers::Reader]
20
18
 
21
- def self.serializers: -> Configuration::ProviderCollection[Serializers::Serializer[Nodes::Node]]
19
+ def self.serializers: [TValue < _Inspect] -> Configuration::ProviderCollection[Serializers::Serializer[Nodes::Node[TValue]]]
22
20
 
23
- def self.compressor: -> Compressor
21
+ def self.compressor: [TValue < _Inspect] -> Compressor[TValue]
24
22
 
25
- def self.root_builder: -> ^() -> Nodes::Node
23
+ def self.root_builder: [TValue < _Inspect] -> ^() -> Nodes::Node[TValue]
26
24
  end
27
25
  end
@@ -4,8 +4,8 @@ module Zip
4
4
 
5
5
  def name: -> String
6
6
 
7
- def extract: (String) -> void
7
+ def extract: (String, ?destination_directory: String?) -> void
8
8
 
9
9
  def each: ?{ (Entry) -> void } -> (Enumerator[Entry, void])
10
10
  end
11
- end
11
+ end
data/sig/lib/zip/file.rbs CHANGED
@@ -1,11 +1,9 @@
1
1
  module Zip
2
2
  class File
3
- CREATE: bool
4
-
5
- def self.open: [TContent] (String, ?bool?) { (File) -> TContent } -> TContent
3
+ def self.open: [TContent] (String, ?create: bool?) { (File) -> TContent } -> TContent
6
4
 
7
5
  def entries: -> Array[Entry]
8
6
 
9
7
  def add: (String, String) -> void
10
8
  end
11
- end
9
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rambling-trie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgar Gonzalez
8
8
  - Lilibeth De La Cruz
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-12-05 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: 'The Rambling Trie is a Ruby implementation of the trie data structure,
15
14
  which includes compression abilities and is designed to be very fast to traverse. '
@@ -56,6 +55,7 @@ files:
56
55
  - lib/rambling/trie/stringifyable.rb
57
56
  - lib/rambling/trie/version.rb
58
57
  - rambling-trie.gemspec
58
+ - sig/lib/nilable.rbs
59
59
  - sig/lib/rambling/trie.rbs
60
60
  - sig/lib/rambling/trie/comparable.rbs
61
61
  - sig/lib/rambling/trie/compressible.rbs
@@ -87,7 +87,6 @@ metadata:
87
87
  changelog_uri: https://github.com/gonzedge/rambling-trie/blob/main/CHANGELOG.md
88
88
  documentation_uri: https://www.rubydoc.info/gems/rambling-trie
89
89
  rubygems_mfa_required: 'true'
90
- post_install_message:
91
90
  rdoc_options: []
92
91
  require_paths:
93
92
  - lib
@@ -95,18 +94,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
94
  requirements:
96
95
  - - ">="
97
96
  - !ruby/object:Gem::Version
98
- version: '3.1'
97
+ version: '3.2'
99
98
  - - "<"
100
99
  - !ruby/object:Gem::Version
101
- version: '4'
100
+ version: '5'
102
101
  required_rubygems_version: !ruby/object:Gem::Requirement
103
102
  requirements:
104
103
  - - ">="
105
104
  - !ruby/object:Gem::Version
106
105
  version: '0'
107
106
  requirements: []
108
- rubygems_version: 3.5.22
109
- signing_key:
107
+ rubygems_version: 4.0.3
110
108
  specification_version: 4
111
109
  summary: A Ruby implementation of the trie data structure.
112
110
  test_files: []