FastSortLibrary 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package FastSortLibrary --version 1.0.1
                    
NuGet\Install-Package FastSortLibrary -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FastSortLibrary" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FastSortLibrary" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="FastSortLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FastSortLibrary --version 1.0.1
                    
#r "nuget: FastSortLibrary, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FastSortLibrary@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FastSortLibrary&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=FastSortLibrary&version=1.0.1
                    
Install as a Cake Tool

Sort faster than Array.Sort(). [Still under debugging]

BothSidesNowSort() : Multi-task. Time is less than half on my intel i5 note(2 core 4 threads). Still, I can't solve unknown reason sort miss.
MiceSort() : Single-task. Time is a little faster. More reliable.

1. Usage

var sort = new SortEnvironment<T>() { // Change T -> class or value type of array
Data = {IList<T> Data}, // Name of T[] or List<T> or other array based structure
Compare = {Comparison<T> Compare}, // Compare function
// InverseOrder = true, // Set true if Descending
// AlmostSorted = true, // Set true if the array is almost sorted (Time may be shortened. Normally time becomes longer.)
// CoreCacheAmount = 256, // Data amount that can be stored each core cache. 2^N. Left value is my PC experimental one and used if this setting is omitted.
// Below setting is only for 'BothSidesNowSort'
// TaskAmount = 4 // Parallel task amount. Environment.ProcessorCount (Thread amount) is used if this setting is omitted.
//  RedZone = true           // Set true if wanting full throttle. Faster but danger. False is more safety under limiter.
};
sort.BothSidesNowSort(); // or sort.MiceSort();

Or call like one of below. Array<T>.Sort() compatible shape.
ArraySort<T>.BothSidesNowSort(T[] Data);
ArraySort<T>.BothSidesNowSort(T[] Data, IComparer<T> Comparer);
ArraySort<T>.BothSidesNowSort(T[] Data, Comparison<T> Compare);
ListSort<T>.BothSidesNowSort(List<T> Data);
ListSort<T>.BothSidesNowSort(List<T> Data, IComparer<T> Comparer);
ListSort<T>.BothSidesNowSort(List<T> Data, Comparison<T> Compare);

2. Character
Method  : In-place merge sort, Bottom-up approach.
Stable : Yes
Memory : [log2(N/M) * 3 * int size * task amount] stack is used. (N is Data length. M is CoreCacheAmount.)
        : I set 100 instead of log2(N/M). [I think it is sufficient safty value and present PC don't mind this size.]
: And additionally, for BothSidesNowSort() multi-core control, [N/M * int size] array is used.
Time    : Comparison: O(NlogN)
        : Move: O(NlogN^2) when N is small, O(NlogN) when N is large. [My persume. Not decision]

3. Notice
- For chalenger and human sacrifice to brand new technology only
  This is good tool for confirming your PC CPU core/thread true ability.
  I still met unknown reason sort miss in continuous tests of "Both sides now sort(RedZone = true)".
  Multi-task occasional bug is very difficult to guess the reason. Still under debugging.
  In my test of present version, all faults are sort misses by some data broken. And when the sort is OK, all data is held.
  And sort miss occurs always background of different application work in my test.
  "Mice sort" or "Both sides now sort(RedZone = flase)" are more reliable.
  But my purpose is only fastest sort. So I have not checked these long time.
- If the comparison function is only subtraction like common sort benchmark, these are slower than Array.Sort().
  Only when comparison function is time consuming, these sorts are faster than Array.Sort().
- This function is available to IList<T> interface implemented array structure class. (T[], List<T>)
  It can't sort LinkedList<T> because the class has no link patch function.
  (C# LinkedList<T> originally has no sort function. Array shape or LinQ(not In-place) may be standard if sorting is necessary in C#.
  I think In-place sort of linked list is possible and there is the demand.)

4. Algorithm
  Below article includes almost theory I using but the list in it includes many bugs. (A little previous version)
https://www.codeproject.com/Articles/5275988/Fastest-Sort-Algorithm

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 1,174 12/24/2021
1.0.3 3,878 11/26/2021
1.0.2 1,129 5/18/2021
1.0.1 1,042 5/4/2021
1.0.0 1,139 4/17/2021

Modify 2 bugs
Add parameter List<T>