Re: [go-nuts] Why is there no pure StableSort in golang.org/x/exp/slices?

2023-04-23 Thread Uli Kunitz
I have written the code now and run a benchmark. In the benchmark function slices.Sort is 9% faster than slices.SortFunc, which is ca. 9% faster than slices.SortStableFunc for my benchmark. I don't need stable sort, but assumed that merge sorting would benefit more from presorted runs. On Sunda

Re: [go-nuts] Why is there no pure StableSort in golang.org/x/exp/slices?

2023-04-22 Thread 'Axel Wagner' via golang-nuts
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

[go-nuts] Why is there no pure StableSort in golang.org/x/exp/slices?

2023-04-22 Thread Uli Kunitz
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 algorith