JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.07k stars 5.43k forks source link

Feature request: Non allocating sort for tuple #54489

Open jw3126 opened 2 months ago

jw3126 commented 2 months ago

I think it would be very cool if one could do e.g.

sort((1,4,5,3))

and it would return a sorted tuple blazing fast without allocs. There are packages in the ecosystem like SortingNetworks.jl that can do this, but they cannot overload Base.sort without piracy. So if sort is used inside some other function it is still slow even on tuples. Would it makes sense to add fast NTuple sort to Base?

LilithHafner commented 2 months ago

We had support for this in https://github.com/JuliaLang/julia/pull/46104. The whole thing got reverted on the grounds of making it harder to define custom sorting functions in a package in a nonbreaking way, but sort(x::NTuple) can and should reland.