levenshtein_lite 0.1.0 → 1.0.1

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: 27f636a2c32c7603879234434d8fc128514448efc77e25cd7dd921ee5cc77e54
4
- data.tar.gz: 6be6e75c4622230a2d7ebc63942bac4353c35c011c7a47851416b704194cf9bb
3
+ metadata.gz: 8ff593c873777192903631e7000215c6953b85ce530f30382d1da7d55fc15661
4
+ data.tar.gz: a06997d04cef02c7e4390c6c6f2ba4082f064c72a76759403106451d835722c7
5
5
  SHA512:
6
- metadata.gz: d2f72d0652980d0ac28442101c61370f341d9e1ee1a0db3e25d0f0835eba8e68cb9adea088cfc67e7770d84d77dfc631abfb3a12d4cf85cc4f31da1fc4843cc0
7
- data.tar.gz: 4ab59b1a3c781e27e04e5e889260ad700050f3f9ba0b136fa5603b1c1582d0a2f84ea8044e23952e20dfd6c8038c754189a81bfa705a7c225f61824482a2f92f
6
+ metadata.gz: 0dbceb45a6a8355a4546b1ebad2f8b19c43e34d784c3798cdcdbe3ea9e382db927f4deae7a9ac6a23764bcdd0b3b31e732412f01a6f0bfaf09121459580e42bf
7
+ data.tar.gz: d55d6cf258f729739732ca797e9fb8435d9bf4aad6229379efb5db866b32f4849b1264437f3f08565b9099ddd6eac8808b496f80f66fb698dae0e81ad2001c5b
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.0"
4
+ VERSION = "1.0.1"
3
5
  end
@@ -1,34 +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
- def self.distance(s1, s2)
5
- return s1.length if s2.empty?
6
- return s2.length if s1.empty?
7
- return 0 if s1 == s2
8
+ # Computes the Levenshtein distance between two strings.
9
+ #
10
+ # @param str1 [String]
11
+ # @param str2 [String]
12
+ # @return [Integer] number of changes to transform str1 to str2
13
+
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
8
20
 
9
- # Distance from a prefix of s1 to each prefix in s2.
21
+ # Distance from a prefix of str1 to each prefix in str2.
10
22
  #
11
- # On the first iteration, the prefix of s1 is just "",
12
- # 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
13
25
  # is the prefix's length. For example, the distance from
14
- # "abc" to "" is 3.
26
+ # 'abc' to '' is 3.
15
27
  #
16
- # So, we initialize the array to [0, 1, 2,.. s2.length].
28
+ # So, we initialize the array to [0, 1, 2,.. str2.length].
17
29
  #
18
- distances = Array.new(s2.length + 1) { _1 }
30
+ distances = Array.new(str2.length + 1) { _1 }
19
31
 
20
32
  # Workspace for calculating the next set of prefix distances.
21
- workspace = Array.new(s2.length + 1)
33
+ workspace = Array.new(str2.length + 1)
22
34
 
23
35
  i = 0 # avoid allocations from each_with_index
24
- s1.each_codepoint do |c1|
36
+ str1.each_codepoint do |c1|
25
37
  workspace[0] = i + 1
26
38
 
27
39
  j = 0 # avoid allocation from each_with_index
28
- s2.each_codepoint do |c2|
40
+ str2.each_codepoint do |c2|
29
41
  deletion_cost = distances[j + 1] + 1
30
42
  insertion_cost = workspace[j] + 1
31
- substitution_cost = distances[j] + (c1 == c2 ? 0 : 1)
43
+ substitution_cost = distances[j] + ((c1 == c2) ? 0 : 1)
32
44
 
33
45
  min = deletion_cost
34
46
  min = insertion_cost if insertion_cost < min
@@ -45,13 +57,17 @@ module LevenshteinLite
45
57
  #
46
58
  # Swap them the old-fashioned way to avoid an Array allocation.
47
59
  #
60
+ # rubocop:disable Style/SwapValues
48
61
  tmp = distances
49
62
  distances = workspace
50
63
  workspace = tmp
64
+ # rubocop:enable Style/SwapValues
51
65
 
52
66
  i += 1
53
67
  end
54
68
 
55
69
  distances[-1]
56
70
  end
71
+ # rubocop:enable Metrics/MethodLength
72
+ # rubocop:enable Metrics/AbcSize
57
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,98 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: levenshtein_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
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: benchmark-ips
70
- requirement: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '2.14'
75
- type: :development
76
- prerelease: false
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '2.14'
82
- - !ruby/object:Gem::Dependency
83
- name: allocation_tracer
84
- requirement: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '0.6'
89
- type: :development
90
- prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '0.6'
11
+ dependencies: []
96
12
  email:
97
13
  - erin.dees@hey.com
98
14
  executables: []
@@ -100,17 +16,18 @@ extensions: []
100
16
  extra_rdoc_files: []
101
17
  files:
102
18
  - CODE_OF_CONDUCT.md
103
- - Gemfile
104
- - Gemfile.lock
105
19
  - LICENSE.txt
106
20
  - README.md
107
- - levenshtein_lite.gemspec
108
21
  - lib/levenshtein_lite.rb
109
22
  - lib/levenshtein_lite/version.rb
23
+ - sig/levenshtein_lite.rbs
24
+ - sig/levenshtein_lite/version.rbs
110
25
  homepage: https://github.com/undees/levenshtein_lite
111
26
  licenses:
112
27
  - MIT
113
- metadata: {}
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
30
+ ruby-signature: RBS
114
31
  rdoc_options: []
115
32
  require_paths:
116
33
  - lib
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,52 +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
-
38
- PLATFORMS
39
- arm64-darwin-24
40
- ruby
41
-
42
- DEPENDENCIES
43
- allocation_tracer!
44
- benchmark-ips (~> 2.14)
45
- bundler (~> 2.6)
46
- faker (~> 3.5)
47
- levenshtein_lite!
48
- rake (~> 13.2)
49
- rspec (~> 3.13)
50
-
51
- BUNDLED WITH
52
- 2.6.7
@@ -1,40 +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 "benchmark-ips", "~> 2.14"
39
- spec.add_development_dependency "allocation_tracer", "~> 0.6"
40
- end