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 Sunday, April 23, 2023 at 8:57:59 AM UTC+2 Axel Wagner wrote:

> 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.k...@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...@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/6f86b936-3149-4f31-800e-0b69cd96a6c5n%40googlegroups.com.

Reply via email to