Revise workspace/buffer to be ::UInt8[] instead of ::AbstractVector{eltype(input)} #45596
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.
The workspace/buffer used in sorting is merely a place to put things. It need not have a fixed type. I believe the most natural way to represent a place to put things is a
Vector{UInt8}
, as suggested originally by cjdoris. The impact of this change is perhaps best understood by seeing how the "sort(x; workspace=w)" test set changes.To use a workspace/buffer, one needs to designate some space
workspace = UInt8[]
and then give that space to multiple different sorting functions, each of which will temporarily assume ownership of that Vector, resize/reinterpret it as needed, and then return ownership back to the caller upon return. To quote cjdoris, "The caller can then preallocate an empty such vector and pass it in to repeated calls without needing to know how it will be used."This is better than
workspace::AbstractVector{eltype(input)}
because it is more natural, extensible, and reusable (subjective) and because it allows for the workspace to be used both to store elements of the input array and to store other relevant collections with different element types like the count vector in radix sort (objective).See discussion leading to this PR here and more recently here. This follows up on #45330.