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

Commit12679b8

Browse files
committed
In levenshtein_internal(), describe algorithm a bit more clearly.
1 parent54c88de commit12679b8

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

‎contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,25 @@ levenshtein_internal(text *s, text *t,
277277
++n;
278278

279279
/*
280-
* Instead of building an (m+1)x(n+1) array, we'll use two different
281-
* arrays of size m+1 for storing accumulated values. At each step one
282-
* represents the "previous" row and one is the "current" row of the
283-
* notional large array.
280+
* One way to compute Levenshtein distance is to incrementally construct
281+
* an (m+1)x(n+1) matrix where cell (i, j) represents the minimum number
282+
* of operations required to transform the first i characters of s into
283+
* the first j characters of t. The last column of the final row is the
284+
* answer.
285+
*
286+
* We use that algorithm here with some modification. In lieu of holding
287+
* the entire array in memory at once, we'll just use two arrays of size
288+
* m+1 for storing accumulated values. At each step one array represents
289+
* the "previous" row and one is the "current" row of the notional large
290+
* array.
284291
*/
285292
prev= (int*)palloc(2*m*sizeof(int));
286293
curr=prev+m;
287294

288-
/* Initialize the "previous" row to 0..cols */
295+
/*
296+
* To transform the first i characters of s into the first 0 characters
297+
* of t, we must perform i deletions.
298+
*/
289299
for (i=0;i<m;i++)
290300
prev[i]=i*del_c;
291301

@@ -297,8 +307,8 @@ levenshtein_internal(text *s, text *t,
297307
inty_char_len=n!=t_bytes+1 ?pg_mblen(y) :1;
298308

299309
/*
300-
*First cell must increment sequentially, as we're onthej'th row of
301-
*the (m+1)x(n+1) array.
310+
*To transform the first 0 characters of s intothefirst j
311+
*characters of t, we must perform j insertions.
302312
*/
303313
curr[0]=j*ins_c;
304314

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp