der: support SetOf sorting on heapless no_std targets
#401
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rust's built-in
[T]::sort_byrequires bothallocand a panic handler, which is limiting forno_stdtargets.This commit switches to using a heapless-friendly insertion sort implementation which is also fallible and can bubble up errors from
DerOrd::der_cmp.Insertion sort is small (<10loc) and should perform well when the input is mostly in order, which should hopefully often be the case for
SetOfconstructors. It also works completely in-place and is thus friendly to heapless targets.This PR replaces the previous
[T]::sort_byapproach used bySetOfVec, which included a workaround which handledDerOrd::der_cmperrors by returningOrdering::Lessand doing a second pass over the results to check they were correctly ordered. This might provide better performance and be worth bringing back, but for now this PR chooses instead to consolidate on a single, well-tested implementation.Testing is performed using proptest, to check equivalence with Rust's built-in
[T]::sort_by.