-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
std.sort.pdq use correct recursion depth #24403
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
base: master
Are you sure you want to change the base?
Conversation
Well, I tried to fix the bug but the checks just keep failing. I don't understand how this minor change can break the builds. |
Take a look at the start of the stack trace:
We're failing an Lines 1261 to 1264 in 1c73b25
Yep -- so, we're calling Since there are no steps involved in sorting zero elements, you should be able to solve this simply by short-circuiting that case at the very top of the function like this: if (a == b) return; |
I think it's better to assert |
Isn't that a bit dangerous? All the popular programming languages just do nothing without errors. That might also break some existing Zig programs. On the other hand selection algorithms are a bit more complicated.
IMHO sorting algorithms should work with zero length slices, but with selection algorithms we should behave more like Rust. At least check with |
I don't see any reason sorting functions should require a non-empty input. Sorting a zero-length slice is well-defined with obvious behavior, and it requires either no special handling or in the worst case one trivial check. |
Fixes #24399