levenshtein_lite 0.1.1 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce4995228336554062336c04a16368324043b3d4a780a895f0a524f800245f0c
4
- data.tar.gz: f3272a1233444d9580d7a2dc5e47741d7bc7f0538c64d214ed735fa7b18d5ae5
3
+ metadata.gz: 911970c161e28d9aa2e9e627cd4fb3b2fd2743faa59979f1fa8f19a933b1f07b
4
+ data.tar.gz: 004231fb15e7628ec6500d6e9750df716aed2943c4ab4283d71fcbc103f506f4
5
5
  SHA512:
6
- metadata.gz: 95c1cc31fc656b386de392b414a0916a087b8697d61dea2f0f8fce36758222ebae1f36f46387a3186d025bf616f19bedbaf08320498a8760075f263fa2d48875
7
- data.tar.gz: 3f5246eb2b58d5c5331bcce5fcb9375d910982916bdf2e217587a378fe2fa724907cdcdeccaa119c56ff7007a895d9b25313b74932f39d85fb61707b31960be8
6
+ metadata.gz: 9e32aa105759a39bfd2338b640461219b23000ee26b3ba476820665040122238ecb5bbdc03082eceead0265f271980010d2b52612e36d1a031823156a4d8c7d5
7
+ data.tar.gz: b9cca06d4c840f28929b2ca078dc628432ee541a0e7c8513e51b1c4e103cf11f0f24e92af96a56f9ca2642b7948f8790463a707f40e40d7810b06cb63fbf05bb
data/CODE_OF_CONDUCT.md CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at erin.paget@clio.com. All
58
+ reported by contacting the project team at erin.dees@hey.com. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # levenshtein_lite
2
2
 
3
+ - [![CI](https://github.com/undees/levenshtein_lite/actions/workflows/ci.yml/badge.svg)](https://github.com/undees/levenshtein_lite/actions/workflows/ci.yml)
4
+ - [![Gem Version](https://img.shields.io/gem/v/levenshtein_lite.svg)](https://rubygems.org/gems/levenshtein_lite)
5
+
3
6
  A fast, hand-tuned, Unicode-aware, allocation-savvy implementation of the Levenshtein string distance algorithm.
4
7
 
5
8
  ## Installation
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LevenshteinLite
2
- VERSION = "0.1.1"
4
+ VERSION = "1.0.2"
3
5
  end
@@ -1,40 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "levenshtein_lite/version"
2
4
 
5
+ # Pure-Ruby implementation of the Levenshtein algorithm,
6
+ # tuned for speed and minimal allocations.
3
7
  module LevenshteinLite
4
8
  # Computes the Levenshtein distance between two strings.
5
9
  #
6
- # @param s1 [String]
7
- # @param s2 [String]
8
- # @return [Integer] number of changes to transform s1 to s2
10
+ # @param str1 [String]
11
+ # @param str2 [String]
12
+ # @return [Integer] number of changes to transform str1 to str2
9
13
 
10
- def self.distance(s1, s2)
11
- return s1.length if s2.empty?
12
- return s2.length if s1.empty?
13
- return 0 if s1 == s2
14
+ # rubocop:disable Metrics/AbcSize
15
+ # rubocop:disable Metrics/MethodLength
16
+ def self.distance(str1, str2)
17
+ return str1.length if str2.empty?
18
+ return str2.length if str1.empty?
19
+ return 0 if str1 == str2
14
20
 
15
- # Distance from a prefix of s1 to each prefix in s2.
21
+ # Distance from a prefix of str1 to each prefix in str2.
16
22
  #
17
- # On the first iteration, the prefix of s1 is just "",
18
- # and so the distance measurement for any prefix of s2
23
+ # On the first iteration, the prefix of str1 is just '',
24
+ # and so the distance measurement for any prefix of str2
19
25
  # is the prefix's length. For example, the distance from
20
- # "abc" to "" is 3.
26
+ # 'abc' to '' is 3.
21
27
  #
22
- # So, we initialize the array to [0, 1, 2,.. s2.length].
28
+ # So, we initialize the array to [0, 1, 2,.. str2.length].
23
29
  #
24
- distances = Array.new(s2.length + 1) { _1 }
30
+ distances = Array.new(str2.length + 1) { _1 }
25
31
 
26
32
  # Workspace for calculating the next set of prefix distances.
27
- workspace = Array.new(s2.length + 1)
33
+ workspace = Array.new(str2.length + 1)
28
34
 
29
35
  i = 0 # avoid allocations from each_with_index
30
- s1.each_codepoint do |c1|
36
+ str1.each_codepoint do |c1|
31
37
  workspace[0] = i + 1
32
38
 
33
39
  j = 0 # avoid allocation from each_with_index
34
- s2.each_codepoint do |c2|
40
+ str2.each_codepoint do |c2|
35
41
  deletion_cost = distances[j + 1] + 1
36
42
  insertion_cost = workspace[j] + 1
37
- substitution_cost = distances[j] + (c1 == c2 ? 0 : 1)
43
+ substitution_cost = distances[j] + ((c1 == c2) ? 0 : 1)
38
44
 
39
45
  min = deletion_cost
40
46
  min = insertion_cost if insertion_cost < min
@@ -51,13 +57,17 @@ module LevenshteinLite
51
57
  #
52
58
  # Swap them the old-fashioned way to avoid an Array allocation.
53
59
  #
60
+ # rubocop:disable Style/SwapValues
54
61
  tmp = distances
55
62
  distances = workspace
56
63
  workspace = tmp
64
+ # rubocop:enable Style/SwapValues
57
65
 
58
66
  i += 1
59
67
  end
60
68
 
61
69
  distances[-1]
62
70
  end
71
+ # rubocop:enable Metrics/MethodLength
72
+ # rubocop:enable Metrics/AbcSize
63
73
  end
@@ -0,0 +1,4 @@
1
+ # lib/levenshtein_lite/version.rb
2
+ module LevenshteinLite
3
+ VERSION: String
4
+ end
@@ -0,0 +1,4 @@
1
+ # lib/levenshtein_lite.rb
2
+ module LevenshteinLite
3
+ def self.distance: (String, String) -> Integer
4
+ end
metadata CHANGED
@@ -1,131 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: levenshtein_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erin Paget
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: bundler
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '2.6'
19
- type: :development
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '2.6'
26
- - !ruby/object:Gem::Dependency
27
- name: rake
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '13.2'
33
- type: :development
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '13.2'
40
- - !ruby/object:Gem::Dependency
41
- name: rspec
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '3.13'
47
- type: :development
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '3.13'
54
- - !ruby/object:Gem::Dependency
55
- name: faker
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '3.5'
61
- type: :development
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '3.5'
68
- - !ruby/object:Gem::Dependency
69
- name: yard
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '0.9'
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '0.9'
82
- - !ruby/object:Gem::Dependency
83
- name: benchmark-ips
84
- requirement: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '2.14'
89
- type: :development
90
- prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '2.14'
96
- - !ruby/object:Gem::Dependency
97
- name: allocation_tracer
98
- requirement: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '0.6'
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '0.6'
11
+ dependencies: []
110
12
  email:
111
13
  - erin.dees@hey.com
112
14
  executables: []
113
15
  extensions: []
114
16
  extra_rdoc_files: []
115
17
  files:
116
- - ".yardopts"
117
18
  - CODE_OF_CONDUCT.md
118
- - Gemfile
119
- - Gemfile.lock
120
19
  - LICENSE.txt
121
20
  - README.md
122
- - levenshtein_lite.gemspec
123
21
  - lib/levenshtein_lite.rb
124
22
  - lib/levenshtein_lite/version.rb
23
+ - sig/levenshtein_lite.rbs
24
+ - sig/levenshtein_lite/version.rbs
125
25
  homepage: https://github.com/undees/levenshtein_lite
126
26
  licenses:
127
27
  - MIT
128
- metadata: {}
28
+ metadata:
29
+ homepage_uri: https://github.com/undees/levenshtein_lite
30
+ rubygems_mfa_required: 'true'
31
+ ruby-signature: RBS
129
32
  rdoc_options: []
130
33
  require_paths:
131
34
  - lib
data/.yardopts DELETED
@@ -1 +0,0 @@
1
- lib/**/*.rb
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- gemspec
6
-
7
- group :development do
8
- gem "allocation_tracer", git: "https://github.com/undees/allocation_tracer.git", ref: "57652f67085bb208abe4c34d21229f06efd05856"
9
- end
data/Gemfile.lock DELETED
@@ -1,54 +0,0 @@
1
- GIT
2
- remote: https://github.com/undees/allocation_tracer.git
3
- revision: 57652f67085bb208abe4c34d21229f06efd05856
4
- ref: 57652f67085bb208abe4c34d21229f06efd05856
5
- specs:
6
- allocation_tracer (0.6.3)
7
-
8
- PATH
9
- remote: .
10
- specs:
11
- levenshtein_lite (0.1.0)
12
-
13
- GEM
14
- remote: https://rubygems.org/
15
- specs:
16
- benchmark-ips (2.14.0)
17
- concurrent-ruby (1.3.5)
18
- diff-lcs (1.6.2)
19
- faker (3.5.1)
20
- i18n (>= 1.8.11, < 2)
21
- i18n (1.14.7)
22
- concurrent-ruby (~> 1.0)
23
- rake (13.2.1)
24
- rspec (3.13.0)
25
- rspec-core (~> 3.13.0)
26
- rspec-expectations (~> 3.13.0)
27
- rspec-mocks (~> 3.13.0)
28
- rspec-core (3.13.3)
29
- rspec-support (~> 3.13.0)
30
- rspec-expectations (3.13.4)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.13.0)
33
- rspec-mocks (3.13.4)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.13.0)
36
- rspec-support (3.13.3)
37
- yard (0.9.37)
38
-
39
- PLATFORMS
40
- arm64-darwin-24
41
- ruby
42
-
43
- DEPENDENCIES
44
- allocation_tracer!
45
- benchmark-ips (~> 2.14)
46
- bundler (~> 2.6)
47
- faker (~> 3.5)
48
- levenshtein_lite!
49
- rake (~> 13.2)
50
- rspec (~> 3.13)
51
- yard (~> 0.9)
52
-
53
- BUNDLED WITH
54
- 2.6.7
@@ -1,41 +0,0 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "levenshtein_lite/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "levenshtein_lite"
8
- spec.version = LevenshteinLite::VERSION
9
- spec.authors = ["Erin Paget"]
10
- spec.email = ["erin.dees@hey.com"]
11
-
12
- spec.summary = %q{Fast, allocation-lite, Unicode-aware Levenshtein distance in pure Ruby.}
13
- spec.homepage = "https://github.com/undees/levenshtein_lite"
14
- spec.license = "MIT"
15
-
16
- spec.required_ruby_version = "~> 3.0"
17
-
18
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
- `git ls-files -z`.split("\x0").reject do |f|
20
- f.match(%r{^(spec|bin|benchmark)/}) ||
21
- %w[
22
- .rspec
23
- .gitignore
24
- .travis.yml
25
- .ruby-version
26
- Rakefile
27
- ].include?(f)
28
- end
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- spec.add_development_dependency "bundler", "~> 2.6"
35
- spec.add_development_dependency "rake", "~> 13.2"
36
- spec.add_development_dependency "rspec", "~> 3.13"
37
- spec.add_development_dependency "faker", "~> 3.5"
38
- spec.add_development_dependency "yard", "~> 0.9"
39
- spec.add_development_dependency "benchmark-ips", "~> 2.14"
40
- spec.add_development_dependency "allocation_tracer", "~> 0.6"
41
- end