It has not been added because it is pointless. Stable sorting is generally
slower than regular sorting, as it puts extra constraints on the output and
keeping to those makes things slower. And for a total order, *every*
sorting algorithm produces a stable sort, as stability only matters if you
have distinguishable but not ordered elements, which can't happen for total
orders. Discounting NaN and ±0 issues, < is a total order and it doesn't
seem worth it to add a new API for the sole purpose of promising to sort
NaNs stably.

On Sun, Apr 23, 2023 at 8:05 AM Uli Kunitz <uli.kun...@gmail.com> wrote:

> I have a use case where I have to sort int32 slices repeatedly that are
> already partially sorted.  (Imagine a tree of smaller non-overlapping
> segments of the same slice, where sorting starts at the bottom and moves to
> the top and the results of the individual sorts are required for the
> algorithm.) Speed is critical for the use case. The StableSort method is an
> excellent first approach for it, because it uses the SymMerge algorithm and
> for small blocks InsertionSort benefiting from pre-sorted runs. Small
> performance improvements benefit the use case, so I looked at
> golang.org/x/exp/slices which contains a SortStableFunc but not a pure
> SortStable method, which I would like to use because I need only the order
> implied by the default less-than (<) operator. For non-stable sorting there
> is pure Sort function, so I wonder why SortStable has been left out. Has it
> not been added because of the NAN issue?
>
> For now I can live with SortStableFunc since I plan a custom sort using
> the knowledge of the positions of the sorted sub-segments,  but I'm puzzled
> about the lack of a pure SortStable.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/89ad151a-a604-45d5-a6a4-620c0024060an%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/89ad151a-a604-45d5-a6a4-620c0024060an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfF4VzZx%3DGR6%3DfNFrgjKuzEtLrOEn9UduwqUrotJhq%2BeHA%40mail.gmail.com.

Reply via email to