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

Fix kSmallest exponent bug #38

Merged
merged 1 commit into from
Mar 13, 2023

Conversation

Barbarrosa
Copy link
Contributor

@Barbarrosa Barbarrosa commented Mar 11, 2023

This fixes a bug where the calculation for the cloned tree depth in kSmallest could overflow, which caused a truncation of the tree. This would start filling the resulting array with incorrect values once at least a number of results was pulled about equal to the tree depth. The remainder of the array would be filled with with undefined values.

This still appears to offer a modest performance improvement over the code in 0.7.2 while avoiding the bug that was introduced in 0.7.3. I settled on this implementation after experimenting with the following.

  • Hybrid bit shifting (<<) and exponentiation (both Math.pow and **) split at ~31 bits
  • BigInt conversion
  • String-based bit shifting
  • More conditional logic
  • Looping w/ multiplication

@staltz
Copy link

staltz commented Mar 12, 2023

Thank you!! I can confirm that this patch fixes the test suite in jitdb.

@lemire lemire merged commit 4369c29 into lemire:master Mar 13, 2023
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

Successfully merging this pull request may close these issues.

3 participants