#min #max #sort #iterator #slice

no-std out

Provides functionality to get the n largest items from slices and iterators

25 releases (13 stable)

✓ Uses Rust 2018 edition

new 3.1.2 Aug 12, 2019
3.0.0 Jul 14, 2019
2.0.7 Jul 3, 2019
2.0.4 Mar 25, 2019
0.2.1 Aug 20, 2017

#35 in Algorithms

Download history 2/week @ 2019-04-29 28/week @ 2019-05-06 43/week @ 2019-05-13 113/week @ 2019-05-20 43/week @ 2019-05-27 61/week @ 2019-06-03 30/week @ 2019-06-10 88/week @ 2019-06-17 190/week @ 2019-06-24 165/week @ 2019-07-01 252/week @ 2019-07-08 12/week @ 2019-07-15 85/week @ 2019-07-22 18/week @ 2019-07-29 135/week @ 2019-08-05

414 downloads per month

MIT/Apache

19KB
244 lines

out

Travis Crates.io Docs

Provides functionality to get the n largest items from slices and iterators.

let mut v = [-5, 4, 1, -3, 2];
let max = out::max(&mut v, 3);
assert_eq!(max, [1, 2, 4]);

This library can provide significant performance increase compared to sorting or converting to a heap when n is relatively small compared to the length of the slice or iterator.

Benchmarks

n = 100, len = 1_000_000:

openSUSE Tumbleweed, i7-5820K @ 3.30GHz, and 16GiB RAM:

binary_heap              6,599,355 ns/iter (+/- 84,674)
max                        669,726 ns/iter (+/- 13,595)
max_by_cached_key        1,427,183 ns/iter (+/- 67,828)
max_from_iter              941,276 ns/iter (+/- 47,574)
max_from_iter_unstable     944,383 ns/iter (+/- 120,882)
max_unstable               635,435 ns/iter (+/- 9,683)
sort                    62,585,547 ns/iter (+/- 1,361,258)
sort_by_cached_key      70,672,779 ns/iter (+/- 7,625,703)
sort_unstable           34,595,265 ns/iter (+/- 739,255)

openSUSE Leap 15.0, i7-7700 @ 3.60GHz, and 32GiB RAM:

binary_heap              5,521,422 ns/iter (+/- 124,780) 
max                        653,428 ns/iter (+/- 13,913) 
max_unstable               524,200 ns/iter (+/- 61,033) 
sort                    41,428,917 ns/iter (+/- 486,681) 
sort_unstable           26,124,912 ns/iter (+/- 439,856)

Windows 10 Pro, i7-5820K @ 3.30GHz, and 16GiB RAM:

binary_heap              8,550,850 ns/iter (+/- 1,118,958)
max                      2,282,062 ns/iter (+/- 564,063)
max_unstable             2,179,817 ns/iter (+/- 741,751)
sort                    67,915,490 ns/iter (+/- 5,252,960)
sort_unstable           34,022,120 ns/iter (+/- 3,745,490)

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps