adqselect

Crates.ioadqselect
lib.rsadqselect
version0.1.5
created_at2020-08-13 11:34:33.63996+00
updated_at2025-11-04 14:51:57.313319+00
descriptionA lightweight crate that brings an implementation of nth_element by using the adaptive quickselect algorithm by Andrei Alexandrescu.
homepage
repositoryhttps://github.com/frjnn/adqselect
max_upload_size
id276197
size3,448,548
Jan (frjnn)

documentation

README

adqselect

License: MIT frjnn codecov

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:

[dependencies]
adqselect = "0.1.5"

Usage

use adqselect::nth_element;

fn main() {
    let mut v = vec![10, 7, 9, 7, 2, 8, 8, 1, 9, 4];
    nth_element(&mut v, 3, &mut Ord::cmp);

    assert_eq!(v[3], 7);
}

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

Fast Deterministic Selection (Andrei Alexandrescu, 2016)

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.

Results

Violin Plot

Violin Plot

This chart shows the relationship between function/parameter and iteration time. The thickness of the shaded region indicates the probability that a measurement of the given function/parameter would take a particular length of time.

Line Chart

Line Chart

This chart shows the mean measured time for each function as the input (or the size of the input) increases.

adqselect on 1.000 random unsigned integers

PDF of Slope Regression

adqselect on 10.000 random unsigned integers

PDF of Slope Regression

adqselect on 100.000 random unsigned integers

PDF of Slope Regression

adqselect on 1.000.000 random unsigned integers

PDF of Slope Iteration Times

floydrivest on 1.000 random unsigned integers

PDF of Slope Regression

floydrivest on 10.000 random unsigned integers

PDF of Slope Regression

floydrivest on 100.000 random unsigned integers

PDF of Slope Regression

floydrivest on 1.000.000 random unsigned integers

PDF of Slope Iteration Times

kth on 1.000 random unsigned integers

PDF of Slope Regression

kth on 10.000 random unsigned integers

PDF of Slope Regression

kth on 100.000 random unsigned integers

PDF of Slope Regression

kth on 1.000.000 random unsigned integers

PDF of Slope Iteration Times

order_stat on 1.000 random unsigned integers

PDF of Slope Regression

order_stat on 10.000 random unsigned integers

PDF of Slope Regression

order_stat on 100.000 random unsigned integers

PDF of Slope Regression

order_stat on 1.000.000 random unsigned integers

PDF of Slope Iteration Times

pdqselect on 1.000 random unsigned integers

PDF of Slope Regression

pdqselect on 10.000 random unsigned integers

PDF of Slope Regression

pdqselect on 100.000 random unsigned integers

PDF of Slope Regression

pdqselect on 1.000.000 random unsigned integers

PDF of Slope Iteration Times
Commit count: 0

cargo fmt