levenshtein_lite 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 27f636a2c32c7603879234434d8fc128514448efc77e25cd7dd921ee5cc77e54
4
+ data.tar.gz: 6be6e75c4622230a2d7ebc63942bac4353c35c011c7a47851416b704194cf9bb
5
+ SHA512:
6
+ metadata.gz: d2f72d0652980d0ac28442101c61370f341d9e1ee1a0db3e25d0f0835eba8e68cb9adea088cfc67e7770d84d77dfc631abfb3a12d4cf85cc4f31da1fc4843cc0
7
+ data.tar.gz: 4ab59b1a3c781e27e04e5e889260ad700050f3f9ba0b136fa5603b1c1582d0a2f84ea8044e23952e20dfd6c8038c754189a81bfa705a7c225f61824482a2f92f
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at erin.paget@clio.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
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 ADDED
@@ -0,0 +1,52 @@
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
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Erin Paget
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # levenshtein_lite
2
+
3
+ A fast, hand-tuned, Unicode-aware, allocation-savvy implementation of the Levenshtein string distance algorithm.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'levenshtein_lite'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install levenshtein_lite
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ LevenshteinLite.distance("la", "là") # => 1
25
+ ```
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/undees/levenshtein_lite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the LevenshteinLite project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/levenshtein_lite/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,3 @@
1
+ module LevenshteinLite
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,57 @@
1
+ require "levenshtein_lite/version"
2
+
3
+ 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
+
9
+ # Distance from a prefix of s1 to each prefix in s2.
10
+ #
11
+ # On the first iteration, the prefix of s1 is just "",
12
+ # and so the distance measurement for any prefix of s2
13
+ # is the prefix's length. For example, the distance from
14
+ # "abc" to "" is 3.
15
+ #
16
+ # So, we initialize the array to [0, 1, 2,.. s2.length].
17
+ #
18
+ distances = Array.new(s2.length + 1) { _1 }
19
+
20
+ # Workspace for calculating the next set of prefix distances.
21
+ workspace = Array.new(s2.length + 1)
22
+
23
+ i = 0 # avoid allocations from each_with_index
24
+ s1.each_codepoint do |c1|
25
+ workspace[0] = i + 1
26
+
27
+ j = 0 # avoid allocation from each_with_index
28
+ s2.each_codepoint do |c2|
29
+ deletion_cost = distances[j + 1] + 1
30
+ insertion_cost = workspace[j] + 1
31
+ substitution_cost = distances[j] + (c1 == c2 ? 0 : 1)
32
+
33
+ min = deletion_cost
34
+ min = insertion_cost if insertion_cost < min
35
+ min = substitution_cost if substitution_cost < min
36
+
37
+ workspace[j + 1] = min
38
+
39
+ j += 1
40
+ end
41
+
42
+ # The newly completed workspace becomes the set of distances
43
+ # for the next iteration, and the old distances become our
44
+ # next workspace.
45
+ #
46
+ # Swap them the old-fashioned way to avoid an Array allocation.
47
+ #
48
+ tmp = distances
49
+ distances = workspace
50
+ workspace = tmp
51
+
52
+ i += 1
53
+ end
54
+
55
+ distances[-1]
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: levenshtein_lite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Erin Paget
8
+ bindir: exe
9
+ cert_chain: []
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'
96
+ email:
97
+ - erin.dees@hey.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - CODE_OF_CONDUCT.md
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.md
107
+ - levenshtein_lite.gemspec
108
+ - lib/levenshtein_lite.rb
109
+ - lib/levenshtein_lite/version.rb
110
+ homepage: https://github.com/undees/levenshtein_lite
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '3.0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.6.7
129
+ specification_version: 4
130
+ summary: Fast, allocation-lite, Unicode-aware Levenshtein distance in pure Ruby.
131
+ test_files: []