SmartSortingAPI 1.0.0
dotnet add package SmartSortingAPI --version 1.0.0
NuGet\Install-Package SmartSortingAPI -Version 1.0.0
<PackageReference Include="SmartSortingAPI" Version="1.0.0" />
paket add SmartSortingAPI --version 1.0.0
#r "nuget: SmartSortingAPI, 1.0.0"
// Install SmartSortingAPI as a Cake Addin #addin nuget:?package=SmartSortingAPI&version=1.0.0 // Install SmartSortingAPI as a Cake Tool #tool nuget:?package=SmartSortingAPI&version=1.0.0
Smart Sorting API
Sort algorithms library to use with .NET Standard. All algorithms work over arrays and enumerations of items that implement IComparable<T> interface.
The following algorithms are implemented:
- Bubble Sort
- Heap Sort
- Insertion Sort
- Merge Sort
- Quick Sort
- Selection Sort
How to use
To use extension methods to sort data, add the following code block at the top of your .CS file:
using SmartSorting.Extensions.SortableExtensions;
If you prefer, you can create instances by hand of the sort algorithms from SmartSorting.Algorithms
namespace.
Sorting arrays
To sort an array, use extension method SortUsing
as below:
int[] array = { 1, 3, 4, 5, 2 };
array.SortUsing(ESortAlgorithm.BubbleSort, ESortOrder.Ascending);
The first parameter defines the algorithm to sort the data structure, and the second one indicates wheter we want to sort data in ascending or descending direction.
Sorting Enumerations
You can sort every data structure that implements IEnumerable<T>
calling SortUsing
:
var integerEnumeration = new List<int> { 1, 3, 5, 4, 2 };
var orderedEnumeration = integerEnumeration.SortUsing(ESortAlgorithm.MergeSort, ESortOrder.Descending);
Sorting Enumerations of Custom Types
You can also sort arrays and enumerations of your own types and also type from .NET library that implement IComparable<T>
. Let's take a look at the following example:
public class TodoItem : IComparable<TodoItem>
{
public int Id { get; private set; }
public TodoItem(int id)
{
this.Id = id;
}
public int CompareTo(TodoItem other)
{
return this.Id.CompareTo(other.Id);
}
}
The TodoItem
class implements a comparison between other items of the same type by comparing the IDs. With this implementation we have a way to check which items are "smaller than", "bigger than" or equals to others. This way we can sort arrays or enumerations of this type:
var enumeration = new List<TodoItem>
{
new TodoItem(1),
new TodoItem(5),
new TodoItem(3),
new TodoItem(2),
new TodoItem(4),
};
var orderedEnumeration = enumeration.SortUsing(ESortAlgorithm.SelectionSort, ESortOrder.Ascending);
Fast Sorting with Multiple Algorithms
Sometimes we are not sure about which algorithm will sort our enumeration faster. The library provides an extensions method which we can call to run many sort algorithms asynchronously over an enumeration, this way getting the sorted data structure from the first algorithm that finished its execution.
var enumeration = new List<TodoItem>
{
new TodoItem(1),
new TodoItem(5),
new TodoItem(3),
new TodoItem(2),
new TodoItem(4),
};
var resultingEnumeration = await enumeration.FastSortUsingAsync(ESortOrder.Ascending, ESortAlgorithm.BubbleSort, ESortAlgorithm.InsertionSort);
Product | Versions 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. |
.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. |
This package has 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.0 | 802 | 9/25/2018 |