Skip to content

Commit

Permalink
Merge 768be22 into dc7cb17
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzedge committed May 14, 2023
2 parents dc7cb17 + 768be22 commit c0a6a6f
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 47 deletions.
31 changes: 30 additions & 1 deletion .codeclimate.yml
@@ -1,2 +1,31 @@
exclude_paths:
exclude_patterns:
- 'tasks/'
plugins:
# No to-dos or similar
fixme:
enabled: true
exclude_patterns:
- '.rubocop.*'
# ABC-complexity
flog:
enabled: true
exclude_patterns:
- 'spec/'
# Markdown lint with rules from https://github.com/markdownlint/markdownlint/blob/main/docs/RULES.md
markdownlint:
enabled: true
# Code smells
reek:
enabled: true
exclude_patterns:
- 'spec/'
# Ruby lint
rubocop:
enabled: true
channel: rubocop-1-50-2
# Semgrep Ruby rules
semgrep:
enabled: true
runs:
- configs:
- rules/ruby/lang
4 changes: 4 additions & 0 deletions .mdl_style.rb
@@ -0,0 +1,4 @@
# frozen_string_literal: true

rule 'MD013', line_length: 120
rule 'MD029', style: 'ordered'
1 change: 1 addition & 0 deletions .mdlrc
@@ -0,0 +1 @@
style '.mdl_style.rb'
25 changes: 9 additions & 16 deletions CHANGELOG.md
@@ -1,3 +1,5 @@
# CHANGELOG

## 2.3.2 [compare][compare_v2_3_1_and_master]

## 2.3.1 [compare][compare_v2_3_0_and_v2_3_1]
Expand Down Expand Up @@ -60,7 +62,7 @@
- Add `Readers::Reader` and `Serializer::Serializer` base classes
- Make all readers/serializers extend from their corresponding base classes
- Better docs with `Reader`/`Serializer` and generics
- Fix all code blocks from `\`` to `+` and add some more
- Fix all code blocks from backtick to `+` and add some more
- Add `@return [void]` where appropriate
- Add `@return [self]` where appropriate
- Fix `Nodes::Node` duplicate and broken references
Expand Down Expand Up @@ -319,20 +321,15 @@ Most of these help with the gem's overall performance.

- Add Ruby 2.4 to supported versions by [@gonzedge][github_user_gonzedge]
- Drastically reduce size of gem by [@gonzedge][github_user_gonzedge]

By excluding unnecessary `assets/` and `reports/` when building the gem.
**Size reduction**: from ~472KB to ~21KB.

- By excluding unnecessary `assets/` and `reports/` when building the gem.
- **Size reduction**: from ~472KB to ~21KB.
- Make root node accessible via container by [@gonzedge][github_user_gonzedge]

So that anyone using rambling-trie can develop their custom algorithms

- So that anyone using rambling-trie can develop their custom algorithms
- Expose root node's `#to_a` method through `Container` by
[@gonzedge][github_user_gonzedge]
- Add own `Forwardable#delegate` because of [Ruby 2.4 performance
degradation][ruby_bug_13111] by [@gonzedge][github_user_gonzedge]

Was able to take Creation and Compression benchmarks (~8.8s and ~1.5s
- Was able to take Creation and Compression benchmarks (~8.8s and ~1.5s
respectively) back down to the Ruby 2.3.3 levels by adding own definition of
`Forwardable#delegate`.

Expand Down Expand Up @@ -411,16 +408,12 @@ Most of these help with the gem's overall performance.

- `Rambling::Trie.create` now returns a `Container` instead of a `Root` by
[@gonzedge][github_user_gonzedge]

`Container` exposes these API entry points:

- `Container` exposes these API entry points:
- `#partial_word?` and its alias `#match?`
- `#word?` and its alias `#include?`
- `#add` and its alias `#<<`
- yield the constructed `Container` on `#initialize`

`Rambling::Trie::Node` and its subclasses no longer expose:

- `Rambling::Trie::Node` and its subclasses no longer expose:
- `#match?`
- `#include?`
- `#<<`
Expand Down
11 changes: 7 additions & 4 deletions CONTRIBUTING.md
@@ -1,12 +1,15 @@
## Contributing to Rambling Trie
# Contributing to Rambling Trie

1. If you have found a bug or have a feature request, please [search through the issues][github_issues_all] to see if it has already been reported. If that's not the case, then [create a new one][github_issues_new] with a full description of what you have found or what you need.
2. If you have bug fix or a feature implementation in mind, then [fork Rambling Trie][github_fork] and create a branch with a descriptive name.
1. If you have found a bug or have a feature request, please [search through the issues][github_issues_all] to see if it
has already been reported. If that's not the case, then [create a new one][github_issues_new] with a full description
of what you have found or what you need.
2. If you have bug fix or a feature implementation in mind, then [fork Rambling Trie][github_fork] and create a branch
with a descriptive name.
3. Get the gem up and running locally (tests are written in RSpec):

```sh
bundle install
rake
bundle exec rake
```

4. Implement your bug fix or feature - ***make sure to add tests!***
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -16,7 +16,7 @@ group :development do
end

group :test do
gem 'coveralls_reborn', '~> 0.27.0', require: false
gem 'coveralls_reborn', require: false
gem 'rspec_junit_formatter'
gem 'simplecov', require: false
end
Expand Down
60 changes: 42 additions & 18 deletions README.md
Expand Up @@ -12,7 +12,8 @@
[![Code Climate Grade][code_climate_grade_badge]][code_climate_link]
[![Code Climate Issue Count][code_climate_issues_badge]][code_climate_link]

The Rambling Trie is a Ruby implementation of the [trie data structure][trie_wiki], which includes compression abilities and is designed to be very fast to traverse.
The Rambling Trie is a Ruby implementation of the [trie data structure][trie_wiki], which includes compression abilities
and is designed to be very fast to traverse.

## Installing the Rambling Trie

Expand Down Expand Up @@ -57,7 +58,8 @@ Rambling::Trie.create do |trie|
end
```

Additionally, you can provide the path to a file that contains all the words to be added to the trie, and it will read the file and create the complete structure for you, like this:
Additionally, you can provide the path to a file that contains all the words to be added to the trie, and it will read
the file and create the complete structure for you, like this:

``` ruby
trie = Rambling::Trie.create '/path/to/file'
Expand All @@ -74,7 +76,10 @@ the
trie
```

If you want to use a custom file format, you will need to provide a custom file reader that defines an `#each_word` method that yields each word contained in the file. Look at the [`PlainText` reader][rambling_trie_plain_text_reader] class for an example, and at the [Configuration section][rambling_trie_configuration] to see how to add your own custom file readers.
If you want to use a custom file format, you will need to provide a custom `Reader` that defines an `#each_word` method
that yields each word contained in the file. Look at the [`PlainText` reader][rambling_trie_plain_text_reader] class for
an example, and at the [Configuration section][rambling_trie_configuration] to see how to add your own custom file
readers.

### Operations

Expand All @@ -98,7 +103,8 @@ trie.word? 'word'
trie.include? 'word'
```

If you wish to find if part of a word exists in the trie instance, you should call `#partial_word?` or its alias `#match?`:
If you wish to find if part of a word exists in the trie instance, you should call `#partial_word?` or its
alias `#match?`:

``` ruby
trie.partial_word? 'partial_word'
Expand All @@ -119,7 +125,8 @@ trie.words_within 'ifdxawesome45someword3' # => ['if', 'aw', 'awe', ...]
trie.words_within 'tktktktk' # => []
```

Or, if you're just interested in knowing whether a given string contains any valid words or not, you can use `#words_within?`:
Or, if you're just interested in knowing whether a given string contains any valid words or not, you can
use `#words_within?`:

``` ruby
trie.words_within? 'ifdxawesome45someword3' # => true
Expand All @@ -128,13 +135,15 @@ trie.words_within? 'tktktktk' # => false

### Compression

By default, the Rambling Trie works as a standard trie. Starting from version 0.1.0, you can obtain a compressed trie from the standard one, by using the compression feature. Just call the `#compress!` method on the trie instance:
By default, the Rambling Trie works as a standard trie. Starting from version 0.1.0, you can obtain a compressed trie
from the standard one, by using the compression feature. Just call the `#compress!` method on the trie instance:

``` ruby
trie.compress!
```

This will reduce the size of the trie by using redundant node elimination (redundant nodes are the only-child non-terminal nodes).
This will reduce the size of the trie by using redundant node elimination (redundant nodes are the only-child
non-terminal nodes).

> _**Note**: The `#compress!` method acts over the trie instance it belongs to
> and replaces the root `Node`. Also, adding words after compression (with `#add` or
Expand All @@ -155,7 +164,8 @@ compressed_trie.compressed? # => true

### Enumeration

Starting from version 0.4.2, you can use any `Enumerable` method over a trie instance, and it will iterate over each word contained in the trie. You can now do things like:
Starting from version 0.4.2, you can use any `Enumerable` method over a trie instance, and it will iterate over each
word contained in the trie. You can now do things like:

``` ruby
trie.each { |word| puts word }
Expand All @@ -166,15 +176,19 @@ trie.all? { |word| word.include? 'x' }

### Serialization

Starting from version 1.0.0, you can store a full trie instance on disk and retrieve/use it later on. Loading a trie from disk takes less time, less cpu and less memory than loading every word into the trie every time. This is particularly useful for production applications, when you have word lists that you know are going to be static, or that change with little frequency.
Starting from version 1.0.0, you can store a full trie instance on disk and retrieve/use it later on. Loading a trie
from disk takes less time, less cpu and less memory than loading every word into the trie every time. This is
particularly useful for production applications, when you have word lists that you know are going to be static, or that
change with little frequency.

To store a trie on disk, you can use `.dump` like this:

``` ruby
Rambling::Trie.dump trie, '/path/to/file'
```

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, you can retrieve a previously stored one with `.load` like this:
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,
you can retrieve a previously stored one with `.load` like this:

``` ruby
trie = Rambling::Trie.load '/path/to/file'
Expand All @@ -184,14 +198,15 @@ trie = Rambling::Trie.load '/path/to/file'

Currently, these formats are supported to store tries on disk:

- Ruby's [binary (Marshal)][marshal] format
- [YAML][yaml]
* Ruby's [binary (Marshal)][marshal] format
* [YAML][yaml]

> When dumping into or loading from disk, the format is determined
> automatically based on the file extension, so `.yml` or `.yaml` files will be
> handled through `YAML` and `.marshal` files through `Marshal`.
Optionally, you can use a `.zip` version of the supported formats. In order to do so, you'll have to install the [`rubyzip`][rubyzip] gem:
Optionally, you can use a `.zip` version of the supported formats. In order to do so, you'll have to install
the [`rubyzip`][rubyzip] gem:

``` bash
gem install rubyzip
Expand Down Expand Up @@ -246,7 +261,8 @@ end

### Further Documentation

You can find further API documentation on the autogenerated [rambling-trie gem RubyDoc.info page][rubydoc] or if you want edge documentation, you can go the [GitHub project RubyDoc.info page][rubydoc_github].
You can find further API documentation on the autogenerated [rambling-trie gem RubyDoc.info page][rubydoc] or if you
want edge documentation, you can go the [GitHub project RubyDoc.info page][rubydoc_github].

## Compatible Ruby and Rails versions

Expand All @@ -271,19 +287,27 @@ The Rambling Trie has been tested with the following Ruby versions:

## Contributing to Rambling Trie

Take a look at the [contributing guide][rambling_trie_contributing_guide] to get started, or fire a question to [@gonzedge][github_user_gonzedge].
Take a look at the [contributing guide][rambling_trie_contributing_guide] to get started, or fire a question
to [@gonzedge][github_user_gonzedge].

## License and copyright

Copyright (c) 2012-2023 Edgar González

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

[badge_fury_badge]: https://badge.fury.io/rb/rambling-trie.svg?version=2.3.1
[badge_fury_link]: https://badge.fury.io/rb/rambling-trie
Expand Down
18 changes: 11 additions & 7 deletions spec/integration/rambling/trie_spec.rb
Expand Up @@ -13,24 +13,28 @@
let(:changelog_path) { File.join root_path, 'CHANGELOG.md' }
let(:changelog) { File.read changelog_path }

let(:changelog_versions) do
matches = []
changelog.scan %r{^## (\d+\.\d+\.\d+)} do |match|
matches << match[0]
end
matches
end

it 'matches with the version in the README badge' do
match = %r{\?version=(?<version>.*)$}.match readme
expect(match['version']).to eq Rambling::Trie::VERSION
end

it 'is the version before the one at the top of the CHANGELOG' do
match = %r{## (?<version>\d+\.\d+\.\d+)}.match changelog.split("\n")[0]
changelog_version = Gem::Version.new match['version']
changelog_version = Gem::Version.new changelog_versions.first
lib_version = Gem::Version.new "#{Rambling::Trie::VERSION}.0"
expect(changelog_version).to eq lib_version.bump
end

it 'is included in the CHANGELOG diffs' do
matches = Set.new
changelog.scan %r{^## (\d+\.\d+\.\d+)} do |match|
matches << match[0]
end
expect(matches).to include Rambling::Trie::VERSION
changelog_versions.shift
expect(changelog_versions.first).to eq Rambling::Trie::VERSION
end
end

Expand Down

0 comments on commit c0a6a6f

Please sign in to comment.