<!-- m -->http://siderite.blog... ... tance.html<!-- m -->
It is about 10 times faster then the Levenshtein distance.
It translates to this
MsgBox % Distance( "A H K", "A H Kn" )
MsgBox % Distance( "A H K", "A H K" )
MsgBox % Distance( "A H K", "A h K" )
MsgBox % Distance( "AHK", "" )
MsgBox % Distance( "He", "Ben" )
MsgBox % Distance( "Toralf", "ToRalf" )
MsgBox % Distance( "Toralf", "esromneb" )
MsgBox % Distance( "Toralf", "RalfLaDuce" )
Distance(string1, string2, maxOffset=5) {
StringSplit, n, string1
StringSplit, m, string2
IfEqual n0,0, Return m0
IfEqual m0,0, Return n0
c = 1
offset1 = 0
offset2 = 0
lcs = 0
While((c + offset1 <= n0) && (c + offset2 <= m0)) {
ni := c + offset1
mi := c + offset2
If (n%ni% == m%mi%)
lcs++
else{
offset1 = 0
offset2 = 0
Loop, % maxOffset {
oi := c + A_Index
if ((oi < n0) && (n%oi% == m%c%)) {
offset1 := A_Index
break
}
if ((oi < m0) && (n%c% == m%oi%)) {
offset2 := A_Index
break
}
}
}
c++
}
Return (n0 + m0)/2 - lcs
}
I haven't checked it completly yet, might have bugs.EDIT: Found one bug: fixed, last char wasn't considered
Is there a way to make it faster?




