Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash table not always finding existing nodes #7

Open
mathijs727 opened this issue Sep 16, 2022 · 0 comments
Open

Hash table not always finding existing nodes #7

mathijs727 opened this issue Sep 16, 2022 · 0 comments

Comments

@mathijs727
Copy link
Contributor

mathijs727 commented Sep 16, 2022

There is a bug in the function find_interior_node_in_bucket() in hash_table.h that prevents the hash table from finding some nodes.
When iterating through the memory pages that make up a hash table bucket the loop stops one element too early:

uint32 pageEndIndex = std::min(bucketSize, pindex + C_pageSize);
if (pindex + nodeSize >= pageEndIndex)
    return 0xFFFFFFFF;

// ...

pageEndIndex -= nodeSize;

// ...

for (uint32 index = pindex; index < pageEndIndex;) {
    ...
}

When the page contains only the node we're looking for then pageEndIndex == pindex + nodeSize. However the bounds check if statement will automatically return not found due. This can be easily fixed by changing the comparison operator:

if (pindex + nodeSize > pageEndIndex)
    return 0xFFFFFFFF;

The second issue is the loop itself. At this point the size of the node being searched for has been subtracted from pageEndIndex which now points to the final index in the page that may contain the node without going out of bounds. Hence the comparison operator in the if statement is also wrong and should be greater than or equal:

if (pindex + nodeSize >= pageEndIndex)
    return 0xFFFFFFFF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant