colgreen / Redzen

General purpose C# code library.
Other
94 stars 16 forks source link

TimSort classes: Support sorting of Span<T> instead of T[] #7

Closed colgreen closed 3 years ago

colgreen commented 3 years ago

TimSort (and other sorting classes) will currently sort the items of an Array only. Consider changing this to handling Span instead.

Issue could also be extended to cover wider 'spanification', e.g. SortUnstable() accepts a List, because we rely on List.Sort(), but that ought to accept a Span and use DefaultComparer, or a supplied Comparer. .NET has new support methods for sorting items of a Span. See https://docs.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-5.0