feat(libc): implement heapsort #11400
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11400"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by iAbdulrrahman on 2026-10-26T10:53:12Z.
What
Implement
heapsortinlibcmatching FreeBSD 11 behavior, and add test coverage inGuestQsort.cpp.Tested
Windows 11,
core/libs/tests/GuestQsort.cppwith arrays of various lengths (0,1,2,3,7,16,33,1000), zero element size argument error checking (EINVAL), and null base when count is zero.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:54:00Z.
Review: CHANGES_REQUESTED
Reviewed exact head
d91c3b0de966d48f2243c21e42668b9b08524a22. There is a behavior mismatch with the stated FreeBSD 11 reference: FreeBSD 11.4 heapsort returns success fornmemb <= 1before checking whethersizeis zero. This implementation checkssize == 0first, so zero elements or one element with zero size incorrectly returns-1and setserrno = EINVALinstead of returning0without inspecting the comparator/base.Please put the
count <= 1fast path before the size check and add tests for bothcount == 0andcount == 1withsize == 0(including a null base for the zero-count case). The hosted eligibility, conventions, intake, labels and report checks are still queued; I did not run the product test locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T11:25:14Z.
Review: CHANGES_REQUESTED
The original size/count ordering issue is fixed. Changes requested only to sync the current main base and rerun the focused test as required by CONTRIBUTING.md; see my comment.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T12:15:06Z.
Review: APPROVED
Reviewed exact head
b999ea3c4348e40e0fa738331a250eb6fa4e4ea8. The implementation builds a max heap bottom-up, then extracts the maximum with in-place byte swaps; thecount <= 1early return now precedes size, base, and comparator checks as requested and matches FreeBSD behavior. The zero-size case setsEINVALand leaves the input unchanged. The test covers duplicates, varied lengths, sorted keys, zero/one element no-op cases, and the zero-size error. The author reports rerunning the focused GuestQsort tests after rebasing onto4b1a9a3b2f; interveningmainchanges do not touch these three files. The hosted relinker matrix, ASan, register-context and write-watch checks are green across Linux, Windows and macOS; product jobs are skipped by path policy. I found no remaining blocker.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T12:15:29Z.
Review: APPROVED
Reviewed exact head
b999ea3c4348e40e0fa738331a250eb6fa4e4ea8. The implementation builds a max heap bottom-up, then extracts the maximum with in-place byte swaps; thecount <= 1early return now precedes size, base, and comparator checks as requested and matches FreeBSD behavior. The zero-size case setsEINVALand leaves the input unchanged. The tests cover repeated keys, varied lengths, one/zero-element no-op cases, and the zero-size error. The author reports rerunning the focused GuestQsort tests after syncing to4b1a9a3b2f; subsequentmainchanges do not touch these files, and the hosted relinker matrix, ASan, register-context and write-watch checks pass across Linux, Windows and macOS. Product jobs are skipped by path policy. I found no remaining blocker.