Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #812 from tenderlove/faster_levenshtein

Speed up levenshtein_distance about 18%
  • Loading branch information...
commit d7ac5b43097f59dca6d038d6744efdf57b4571bf 2 parents 673f7c9 + 1ab5475
Eric Hodel drbrain authored
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/rubygems/text.rb
6 lib/rubygems/text.rb
View
@@ -52,11 +52,11 @@ def levenshtein_distance str1, str2
d = (0..m).to_a
x = nil
- n.times do |i|
+ str1.each_char.each_with_index do |char1,i|
e = i+1
- m.times do |j|
- cost = (s[i] == t[j]) ? 0 : 1
+ str2.each_char.each_with_index do |char2,j|
+ cost = (char1 == char2) ? 0 : 1
x = min3(
d[j+1] + 1, # insertion
e + 1, # deletion
Please sign in to comment.
Something went wrong with that request. Please try again.