cvs: php4 /ext/standard levenshtein.c /ext/standard/tests/general_functions 003.phpt

From: Date: Sun, 07 Apr 2002 19:46:45 +0000
Subject: cvs: php4 /ext/standard levenshtein.c /ext/standard/tests/general_functions 003.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10948@lists.php.net to get a copy of this message
hholzgra Sun Apr 7 15:46:45 2002 EDT Modified files: /php4/ext/standard levenshtein.c /php4/ext/standard/tests/general_functions 003.phpt Log: fix and regression test for Bug #16473 Index: php4/ext/standard/levenshtein.c diff -u php4/ext/standard/levenshtein.c:1.22 php4/ext/standard/levenshtein.c:1.23 --- php4/ext/standard/levenshtein.c:1.22 Tue Dec 11 10:30:33 2001 +++ php4/ext/standard/levenshtein.c Sun Apr 7 15:46:45 2002 @@ -15,7 +15,7 @@ | Author: Hartmut Holzgraefe <hartmut@six.de> | +----------------------------------------------------------------------+ */ -/* $Id: levenshtein.c,v 1.22 2001/12/11 15:30:33 sebastian Exp $ */ +/* $Id: levenshtein.c,v 1.23 2002/04/07 19:46:45 hholzgra Exp $ */ #include "php.h" #include <stdlib.h> @@ -40,33 +40,31 @@ if((l1>LEVENSHTEIN_MAX_LENTH)||(l2>LEVENSHTEIN_MAX_LENTH)) return -1; - if(!(p1=emalloc(l2*sizeof(int)))) { + if(!(p1=emalloc((l2+1)*sizeof(int)))) { return -2; } - if(!(p2=emalloc(l2*sizeof(int)))) { + if(!(p2=emalloc((l2+1)*sizeof(int)))) { free(p1); return -2; } - p1[0]=(s1[0]==s2[0])?0:cost_rep; + for(i2=0;i2<=l2;i2++) + p1[i2] = i2*cost_ins; - for(i2=1;i2<l2;i2++) - p1[i2]=i2*cost_ins; - - for(i1=1;i1<l1;i1++) + for(i1=0;i1<l1;i1++) { - p2[0]=i1*cost_del; - for(i2=1;i2<l2;i2++) + p2[0]=p1[0]+cost_del; + for(i2=0;i2<l2;i2++) { - c0=p1[i2-1]+((s1[i1]==s2[i2])?0:cost_rep); - c1=p1[i2]+cost_del; if(c1<c0) c0=c1; - c2=p2[i2-1]+cost_ins; if(c2<c0) c0=c2; - p2[i2]=c0; + c0=p1[i2]+((s1[i1]==s2[i2])?0:cost_rep); + c1=p1[i2+1]+cost_del; if(c1<c0) c0=c1; + c2=p2[i2]+cost_ins; if(c2<c0) c0=c2; + p2[i2+1]=c0; } tmp=p1; p1=p2; p2=tmp; } - c0=p1[l2-1]; + c0=p1[l2]; efree(p1); efree(p2); Index: php4/ext/standard/tests/general_functions/003.phpt diff -u php4/ext/standard/tests/general_functions/003.phpt:1.1 php4/ext/standard/tests/general_functions/003.phpt:1.2 --- php4/ext/standard/tests/general_functions/003.phpt:1.1 Wed Dec 13 18:26:18 2000 +++ php4/ext/standard/tests/general_functions/003.phpt Sun Apr 7 15:46:45 2002 @@ -47,6 +47,12 @@ $n += test_me("bug #6562", 2, "debbbug", "debug"); $n += test_me("bug #6562", 1, "debugging", "debuging"); +$n += test_me("bug #16473", 2, "a", "bc"); +$n += test_me("bug #16473", 2, "xa", "xbc"); +$n += test_me("bug #16473", 2, "xax", "xbcx"); +$n += test_me("bug #16473", 2, "ax", "bcx"); + + echo ($n==0)?"all passed\n":"$n failed\n"; ?>

« previous php.cvs (#10948) next »