Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Std sort fails simple test case #657
Zig version: 0.1.1.c9e01412
sort result: 1,3,2,4,5
Goodness. Thanks for the test case.
There was another problem with the implementation of sort in the standard library, which is that it uses
I had a look at https://en.wikipedia.org/wiki/Sorting_algorithm#Comparison_of_algorithms and only 1 sorting algorithm checked all the boxes:
And that algorithm is Block sort.
I found a high quality implementation of block sort in C, which is licensed under the public domain: https://github.com/BonzaiThePenguin/WikiSort/blob/master/WikiSort.c
I ported the code from C to Zig, integrated it into the standard library, and it passed all tests first try. Amazing.
Surely, I thought, there must be some edge case. So I created a simple fuzz tester:
This test passed as well. And so I think this problem is solved.