You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;fnmain(){letmut v = vec![10,7,9,7,2,8,8,1,9,4];nth_element(&mut v,3,&mutOrd::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.
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
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
adqselect on 10.000 random unsigned integers
adqselect on 100.000 random unsigned integers
adqselect on 1.000.000 random unsigned integers
floydrivest on 1.000 random unsigned integers
floydrivest on 10.000 random unsigned integers
floydrivest on 100.000 random unsigned integers
floydrivest on 1.000.000 random unsigned integers
kth on 1.000 random unsigned integers
kth on 10.000 random unsigned integers
kth on 100.000 random unsigned integers
kth on 1.000.000 random unsigned integers
order_stat on 1.000 random unsigned integers
order_stat on 10.000 random unsigned integers
order_stat on 100.000 random unsigned integers
order_stat on 1.000.000 random unsigned integers
pdqselect on 1.000 random unsigned integers
pdqselect on 10.000 random unsigned integers
pdqselect on 100.000 random unsigned integers
pdqselect on 1.000.000 random unsigned integers
About
Rust nth_element implementation that leverages Andrei Alexandrescu's Adaptive Quickselect algorithm.