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

SortUtils: fix termination condition & enforce unsigned value #28411

Merged
merged 1 commit into from
May 19, 2024

Conversation

sciecode
Copy link
Contributor

Fixes incorrect termination condition during insertion-sort block, exposed by #28401
Informs & enforces unsigned 32b integer sort.


There was a pretty nasty bug in the termination condition of insertion sort, fortunately, it didn't cause wrong results under expected input conditions (uint32). It only became apparent when used with signed values. Nonetheless, it was fixed and unsigned condition is enforced even if input values don't match expected range.

@gkjohnson
Copy link
Collaborator

Thanks for tracking this down! This is a good change, I think, so we don't remove items from the original list. But negative numbers will still result in an incorrect sort, right? Which is okay I just want to make sure I understand.

@gkjohnson gkjohnson added this to the r165 milestone May 18, 2024
@sciecode
Copy link
Contributor Author

But negative numbers will still result in an incorrect sort, right?

That is correct, negative numbers will still be sorted by their 2-complements representation. AKA if you simply bitcast a signed to unsigned in languages like c/c++. Unfortunately radix-sort can't, own its own, solve the problem of signed sorting. It is usually controlled by adjusting the input-keys, like we do in the batch example.

So essentially, this PR is just to make sure that if negative values / overflown 32-bit are inputted, we just don't fail catastrophically as it did previously.

@Mugen87 Mugen87 merged commit 016bdb5 into mrdoob:dev May 19, 2024
11 checks passed
@sciecode sciecode deleted the dev-sort-uint branch May 19, 2024 12:36
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.

None yet

3 participants