Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda07641

Browse files
committed
Fix levenshtein with costs. The previous code multiplied by the cost in only
3 of the 7 relevant locations.Marcin Mank, slightly adjusted by me.
1 parent03d7b06 commitda07641

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

‎contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Joe Conway <mail@joeconway.com>
77
*
8-
* $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.30 2009/06/11 14:48:51 momjian Exp $
8+
* $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.31 2009/12/10 01:54:17 rhaas Exp $
99
* Copyright (c) 2001-2009, PostgreSQL Global Development Group
1010
* ALL RIGHTS RESERVED;
1111
*
@@ -207,13 +207,13 @@ levenshtein_internal(const char *s, const char *t,
207207
n=strlen(t);
208208

209209
/*
210-
*If either m or n is 0, the answer is the other value. This makes sense
211-
*since it would take that many insertions to build a matching string
210+
*We can transform an empty s into t with n insertions, or a non-empty t
211+
*into an empty s with m deletions.
212212
*/
213213
if (!m)
214-
returnn;
214+
returnn*ins_c;
215215
if (!n)
216-
returnm;
216+
returnm*del_c;
217217

218218
/*
219219
* For security concerns, restrict excessive CPU+RAM usage. (This
@@ -241,7 +241,7 @@ levenshtein_internal(const char *s, const char *t,
241241

242242
/* Initialize the "previous" row to 0..cols */
243243
for (i=0;i<m;i++)
244-
prev[i]=i;
244+
prev[i]=i*del_c;
245245

246246
/* Loop through rows of the notional array */
247247
for (y=t,j=1;j<n;y++,j++)
@@ -252,7 +252,7 @@ levenshtein_internal(const char *s, const char *t,
252252
* First cell must increment sequentially, as we're on the j'th row of
253253
* the (m+1)x(n+1) array.
254254
*/
255-
curr[0]=j;
255+
curr[0]=j*ins_c;
256256

257257
for (x=s,i=1;i<m;x++,i++)
258258
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp