Wallace Matthews
2004-Jan-26 16:31 UTC
How match.c hash_search works with multiple checksums that have identical tags
I am trying to understand how match.c works. I am reading the code and something doesnt look quite right. This is usually a sign that I am missing something obvious. Here is what I see. build_hash_table uses qsort to order targets in ascending order of //tag,index// into the array of checksums. It then accesses the targets in ascending order and writes the index at the tag's location in the tag_table. For any set of targets with identical tags, the highest valued index is the resulting value in that location in the table. hash_search initializes "j" from the tag_table resulting in "j" being the largest index in a group of targets with the same tag value. The for loop that uses "j" as its primary iteration control iterates positively (ie. j++). The termination condition for the loop is any tag value that isn't equal to the initialized tag value. It appears to me that only the last target of a group that has an identical tag value will be processed. What am I missing?? wally
Wayne Davison
2004-Jan-27 17:09 UTC
How match.c hash_search works with multiple checksums that have identical tags
On Mon, Jan 26, 2004 at 11:28:44AM -0500, Wallace Matthews wrote:> For any set of targets with identical tags, the highest valued index > is the resulting value in that location in the table.No, it's the lowest index because the loop is run in reverse: for (i = s->count; i-- > 0; ) tag_table[targets[i].t] = i; Thus, the loop that scans the targets with the j++ increment is handling things correctly. ..wayne..