Subject: | severe error with ST_ERROR global variable |
Hi All,
I've encountered one problem with this *very nice* package:
ST_ERROR global variable is used as error code and it's set
to tree_len+10 when each new tree is created.
It's wrong, and it cause problems in some cases.
Thanks in advance,
Dmitry Samborsky
P.S. Detailed info is below (I use Linux & Perl 5.8.0).
Reproducable script:
######################################################
use SuffixTree;
my $str = "mississippi is long river";
my $tree = create_tree($str);
my $query = "ssis";
my $position = find_substring($tree, $query);
printf("Position of '%s' in '%s' is %ld !\n", $query, $str, $position);
# this will redefine ST_ERROR and confuse suffex_tree.c:
my $tree2 = create_tree("x");
$query = "Missuri river";
$position = find_substring($tree, $query);
if ($position > 0 && $position <= length $str) {
printf("\nPosition of '%s' in '%s' is %ld !???\n", $query, $str, $position);
} else {
printf("No '%s' in '%s'\n", $query, $str);
}
######################################################
Desired behaviour:
Position of 'ssis' in 'mississippi is long river' is 3 !
No 'Missuri river' in 'mississippi is long river'
Observed behaviour:
Position of 'ssis' in 'mississippi is long river' is 3 !
Position of 'Missuri river' in 'mississippi is long river' is 11 !???
My 'quick&dirty' patch is:
--- SuffixTree-0.03/suffix_tree.c.orig 2003-01-07 18:16:30.000000000 +0100
+++ SuffixTree-0.03/suffix_tree.c 2005-01-26 16:08:53.000000000 +0100
@@ -572,10 +572,10 @@
else
{
/* One non-matching symbols is found - W is not a substring */
- return ST_ERROR;
+ return 0; /* Samborsky D., samborsky_d@yahoo.com: was ST_ERROR, that is global variable = length(last created tree)+10 and it caused problems !!! */
}
}
- return ST_ERROR;
+ return 0; /* Samborsky D., samborsky_d@yahoo.com: was ST_ERROR, that is global variable = length(last created tree)+10 and it caused problems !!! */
}
/******************************************************************************/