Skip to content

Releases: jonathanpeppers/SortingNetworks

0.1.0

05 May 00:53
a69b573

Choose a tag to compare

🎉 Initial release of SortingNetworks — a .NET source generator that produces sorting-network-based sort methods for small arrays (sizes 2–64) with zero heap allocations.

Highlights

  • Source generator — Decorate any partial class with [SortingNetwork(size, typeof(T))] and get optimized Sort methods at compile time
  • Best-known sorting networks for sizes 2–64, including depth-13 networks for 27 and 28 channels from "Depth-13 Sorting Networks for 28 Channels"
  • SIMD acceleration — Up to 41× faster than Array.Sort on supported hardware:
    • x86: AVX2 and AVX-512 (VBMI) paths for byte, short, int, long, float, double
    • ARM64: AdvSimd/NEON paths for supported types
  • Scalar fallback — Unrolled compare-and-swap codegen for all sizes and types, no SIMD required
  • All primitive types: byte, sbyte, short, ushort, int, uint, long, ulong, nint, nuint, char, float, double, decimal, and string
  • Custom types — Value types implementing IComparable<T> get unrolled .CompareTo() methods; arbitrary types supported via IComparer<T> overloads
  • Span<T> and T[] overloads for both parameterless and IComparer<T> paths
  • Configurable fallback — Define a static OnFallback method to handle sizes outside your declared networks (e.g., delegate to span.Sort())
  • Zero allocations in all generated sort methods

Requirements

  • .NET 8+ for SIMD codegen paths (System.Runtime.Intrinsics)
  • .NET 5+ for scalar-only paths (Unsafe)

Installation

dotnet add package SortingNetworks.SourceGen --version 0.1.0

Quick Start

using SortingNetworks;

[SortingNetwork(27, typeof(int))]
[SortingNetwork(28, typeof(int))]
partial class MySorter { }

Span<int> data = /* 27 elements */;
MySorter.Sort(data); // sorting network