Use Kwker from C# and .NET
The Kwker package works with .NET 8 and later on Linux x86-64 and arm64, macOS arm64 and Windows x64. Every call
takes spans or arrays of any primitive numeric type, from sbyte to ulong, float and double.
The project
dotnet new console -o Latency
cd Latency
dotnet add package Kwker
The program
The three slowest requests, without sorting the whole array (Program.cs):
using Kwker;
var latencyMs = new double[] { 12.1, 250.4, 8.9, 97.0, 310.2, 15.5, 260.0 };
var (values, positions) = Sorter.TopK<double>(latencyMs, 3, Order.Descending);
for (int i = 0; i < values.Length; i++) Console.WriteLine($"{values[i]} at {positions[i]}");
Output
310.2 at 4 260 at 6 250.4 at 1
Build and run
dotnet run -c Release
Errors
Invalid arguments throw ArgumentException, ArgumentOutOfRangeException or ArgumentNullException; the arrays are
left unchanged.
Next steps
- C# API reference: every method, its arguments and exceptions.
- Quickstart: Kwker Core: sorting, order and medians in every language.