adqselect
A lightweight, zero-dependency crate that provides an efficient nth_element implementation in Rust based on Andrei Alexandrescu’s Adaptive Quickselect algorithm.
Available on crates.io.
Installation
Add the crate to your Cargo.toml:
[]
= "0.1.5"
Usage
use nth_element;
nth_element rearranges the vector so that the element at position n is the same as if the vector were fully sorted but runs in O(n) time on average.
The elements before index n are less than or equal to v[n], and those after are greater than or equal.
Implementation
Based on the paper
This algorithm refines the classic Median of Medians approach to achieve strong performance guarantees while remaining practical.
Performance
adqselect guarantees linear deterministic time complexity and is competitive with popular selection crates such as:
Benchmarks
Detailed benchmarks are available in the repository, comparing throughput and allocation efficiency across datasets of varying size and distribution.
License
Licensed under the MIT License.