ARS: Adjacency Run Sort 🚀
arslib is a blazing-fast, cache-friendly, and highly parallel sorting library written in Rust. It implements the Adjacency Run Sort (ARS) algorithm—specifically the 6th Generation "Aero" Architecture. ARS leverages spatial adjacency, cache-line buffering, and multi-threading to achieve extreme performance on modern CPU architectures.
Features
- Extreme Performance: Outperforms traditional sorting algorithms (like Introsort and PDQsort) and often beats highly optimized Radix sorts (like RDST and Voracious) on large datasets.
- Cache-Locality Optimized: Uses stack-allocated micro-buffers to sequentialize writes and maximize L1/L2 cache utilization.
- Parallel by Default: Fully utilizes multi-core processors using
rayon. - Stable & Unstable Variants: Choose between
arslib::sort(unstable) andarslib::sort_stable(stable). - Generic Support: Easily sort any type by implementing the
ARSValuetrait to map your data to a spatialu64representation. Out-of-the-box support for primitives likei32,i64,u64,f64, andString.
Installation
Add this to your Cargo.toml:
[]
= "0.4.0"
Quick Start
use arslib;
Custom Types
To sort your own custom structs, simply implement the ARSValue trait. This trait requires a single method, to_spatial_u64(), which projects your type into a 1D uniform numeric space for histogram analysis.
use ARSValue;
How It Works
ARS (Aero Architecture) operates by performing an initial lightweight parallel analysis to determine dataset boundaries and characteristics. It then projects the data into a mapped spatial domain, dynamically allocates bins, and processes elements in chunks. By buffering elements locally per-thread and flushing them in cache-aligned blocks, it drastically reduces cache misses and main memory latency compared to traditional scattered writes.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.