-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
add qsort as libc extension #28896
Comments
we use gc-sections so I don't see any particular issue with adding to minimal libc since if it is unused, its code won't be included in the binary. |
Ive actually made a PR adding musl libc implementation |
Also covered in #31107 |
Copied from #29804 I have some reservations about just copying from another project, although I haven't looked at the implementation.
I mistakenly opened #31107 for this same topic since I've been carrying qsort.c in my greybus module for a while (from the BSD C library). However, due to the aforementioned concerns, I never bothered to make a PR. @JonBruchim - would you be able to provide some analysis of this vs possibly other algorithms? Just at a quick glance, Block Sort looks promising too. https://en.wikipedia.org/wiki/Block_sort
I guess the only slight advantage that Block Sort might have is that it's stable. Smoothsort looks to have a reasonably simple implementation though. |
Discussed today in the release meeting, this change in #39980 may be backported to 2.7 because it:
It satisfies several requirements of the Minimal LibC
Lastly, it satisfies several criteria for Safety Critical
|
This change implements qsort() for the minimal libc via Heapsort. Heapsort time complexity is O(n log(n)) in the best, average, and worst cases. It is O(1) in space complexity (i.e. sorts in-place) and is iterative rather than recursive. Heapsort is not stable (i.e. does not preserve order of identical elements). On cortex-m0, this implementation occupies ~240 bytes. Fixes zephyrproject-rtos#28896 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change implements qsort() for the minimal libc via Heapsort. Heapsort time complexity is O(n log(n)) in the best, average, and worst cases. It is O(1) in space complexity (i.e. sorts in-place) and is iterative rather than recursive. Heapsort is not stable (i.e. does not preserve order of identical elements). On cortex-m0, this implementation occupies ~240 bytes. Fixes #28896 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change implements qsort() for the minimal libc via Heapsort. Heapsort time complexity is O(n log(n)) in the best, average, and worst cases. It is O(1) in space complexity (i.e. sorts in-place) and is iterative rather than recursive. Heapsort is not stable (i.e. does not preserve order of identical elements). On cortex-m0, this implementation occupies ~240 bytes. Fixes #28896 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
This change implements qsort() for the minimal libc via Heapsort. Heapsort time complexity is O(n log(n)) in the best, average, and worst cases. It is O(1) in space complexity (i.e. sorts in-place) and is iterative rather than recursive. Heapsort is not stable (i.e. does not preserve order of identical elements). On cortex-m0, this implementation occupies ~240 bytes. Fixes #28896 Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
qsort isn't implemented under stdlib
As we would like zephyr to have a small memory footprint,
adding this function to stdlib (as its in the standard c library) will increase the overhead
I would like to add this function under zephyr/lib/libc/minimal/
I would be glad to take this as my first issue in zephyr.
Thanks
The text was updated successfully, but these errors were encountered: