Skip to content

Fix kSmallest exponent bug#38

Merged
lemire merged 1 commit intolemire:masterfrom
Barbarrosa:fix-ksmallest-exponent
Mar 13, 2023
Merged

Fix kSmallest exponent bug#38
lemire merged 1 commit intolemire:masterfrom
Barbarrosa:fix-ksmallest-exponent

Conversation

@Barbarrosa
Copy link
Copy Markdown
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
Copy Markdown

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