Skip Menu |

This queue is for tickets about the Tree-Suffix CPAN distribution.

Report information
The Basics
Id: 23674
Status: resolved
Priority: 0/
Queue: Tree-Suffix

People
Owner: Nobody in particular
Requestors: dk59gjhnd [...] aaronkaplan.info
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: String id and string index are not the same thing
According to your documentation, find() returns (among other things) a string index, and string() takes a string index as its argument, so in principle I should be able to do this: use Tree::Suffix; my $tree = Tree::Suffix->new(); $tree->insert('word0'); $tree->insert('word1'); for my $result ($tree->find('word1')) { my ($index, $start, $end) = @$result; print "[", $tree->string($index), "]\n"; } And in fact I can: it prints [word1] However, if I add a line that calls find() in between the two insert()s, e.g. $tree->insert('word0'); $tree->find('foo'); $tree->insert('word1'); it no longer works--the script now prints the empty string. The problem seems to be that you have confused string ids with string indices. While you claim that the argument of string() is a string index, in fact the function treats its argument as if it were a string id. The index is a field in LST_StringHashItem, whereas the id is a field in LST_String. A new index is generated each time a new string is entered into the tree; a new id is generated each time a new string is *created*, which includes not only calls to insert(), but also calls to find() and perhaps others. This explains why doing a find() before an insert() can change the behavior. I seem to have fixed the problem in my own case by modifying find() so that it returns ids instead of indices, so I can subsequently pass these values as arguments to string(). I imagine this change would break some existing scripts, though. See attached patch. I have not tested it heavily. Note that I had to modify string() as well. My guess is that at some point you noticed a case in which the index being passed to string() wasn't equal to the id of the string it was supposed to retrieve, and you mistakenly thought it was a simple off-by-one error. Also, the doc for strings() says that it returns a list of ids, but it actually returns indices.
Subject: id_index_patch
Download id_index_patch
application/octet-stream 1.3k

Message body not shown because it is not plain text.

thanks for the bug report. as there are already a number of bugs due to the libstree library and the author is no longer maintaining it, it's not practical to maintain this library. it will probably take a while to properly fix the problem you found, but i'll gladly accept a complete patch that passes all test cases. On Tue Nov 28 05:20:54 2006, aaronnathankaplan wrote: Show quoted text
> According to your documentation, find() returns (among other things) a > string index, and string() takes a string index as its argument, so in > principle I should be able to do this: > > use Tree::Suffix; > > my $tree = Tree::Suffix->new(); > > $tree->insert('word0'); > $tree->insert('word1'); > for my $result ($tree->find('word1')) { > my ($index, $start, $end) = @$result; > print "[", $tree->string($index), "]\n"; > } > > And in fact I can: it prints > > [word1] > > However, if I add a line that calls find() in between the two > insert()s, e.g. > > $tree->insert('word0'); > $tree->find('foo'); > $tree->insert('word1'); > > it no longer works--the script now prints the empty string. > > The problem seems to be that you have confused string ids with string > indices. While you claim that the argument of string() is a string > index, in fact the function treats its argument as if it were a string id. > > The index is a field in LST_StringHashItem, whereas the id is a field > in LST_String. A new index is generated each time a new string is > entered into the tree; a new id is generated each time a new string is > *created*, which includes not only calls to insert(), but also calls > to find() and perhaps others. This explains why doing a find() before > an insert() can change the behavior. > > I seem to have fixed the problem in my own case by modifying find() so > that it returns ids instead of indices, so I can subsequently pass > these values as arguments to string(). I imagine this change would > break some existing scripts, though. See attached patch. I have not > tested it heavily. Note that I had to modify string() as well. My > guess is that at some point you noticed a case in which the index being > passed to string() wasn't equal to the id of the string it was supposed > to retrieve, and you mistakenly thought it was a simple off-by-one error. > > Also, the doc for strings() says that it returns a list of ids, but it > actually returns indices.