16 May 03:53
Differing output for function moved from ruby 1.8 to 1.9
From: DJ Jazzy Linefeed <john.d.perkins <at> gmail.com>
Subject: Differing output for function moved from ruby 1.8 to 1.9
Newsgroups: gmane.comp.lang.ruby.general
Date: 2008-05-16 01:55:02 GMT
Subject: Differing output for function moved from ruby 1.8 to 1.9
Newsgroups: gmane.comp.lang.ruby.general
Date: 2008-05-16 01:55:02 GMT
Sup, fools?
This is the Levenshtein function I'm gankin' for my file comparison
project (see "40 million comparison..." thread):
# Levenshtein calculator
# Author: Paul Battley (pbattley <at> gmail.com)
# Modified slightly by John Perkins:
# -- removed $KCODE call
def distance(str1, str2)
unpack_rule = 'C*'
s = str1.unpack(unpack_rule)
t = str2.unpack(unpack_rule)
n = s.length
m = t.length
return m if (0 == n) # stop the madness if either string is empty
return n if (0 == m)
d = (0..m).to_a
x = nil
(0...n).each do |i|
e = i + 1
(0...m).each do |j|
cost = (s[i] == t[j]) ? 0 : 1
x = [
d[j + 1] + 1, # insertion
(Continue reading)
RSS Feed