#partial #sort #iterator #slice

no-std out

Provides partial sorting for slices and iterators

30 releases (18 stable)

✓ Uses Rust 2018 edition

5.0.0 Nov 22, 2019
4.0.2 Oct 27, 2019
4.0.1 Sep 30, 2019
3.1.3 Aug 17, 2019
0.2.1 Aug 20, 2017

#43 in Algorithms

Download history 110/week @ 2019-08-09 16/week @ 2019-08-16 91/week @ 2019-08-23 65/week @ 2019-08-30 116/week @ 2019-09-06 52/week @ 2019-09-13 559/week @ 2019-09-20 64/week @ 2019-09-27 45/week @ 2019-10-04 2/week @ 2019-10-11 86/week @ 2019-10-18 68/week @ 2019-10-25 118/week @ 2019-11-01 43/week @ 2019-11-08 87/week @ 2019-11-15

465 downloads per month

MIT/Apache

21KB
247 lines

out

Travis Crates.io Docs

Provides partial sorting for slices and iterators.

let mut v = [-5, 4, 1, -3, 2];
let max = out::slice::sort(&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 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:

test iter::sort                ... bench:     918,253 ns/iter (+/- 99,863)
test iter::sort_unstable       ... bench:     916,908 ns/iter (+/- 58,050)
test slice::sort               ... bench:     698,643 ns/iter (+/- 46,373)
test slice::sort_by_cached_key ... bench:   1,516,099 ns/iter (+/- 37,853)
test slice::sort_unstable      ... bench:     655,286 ns/iter (+/- 25,017)
test std::binary_heap          ... bench:   6,592,801 ns/iter (+/- 780,590)
test std::sort                 ... bench:  63,192,028 ns/iter (+/- 2,338,506)
test std::sort_by_cached_key   ... bench:  66,058,834 ns/iter (+/- 5,447,387)
test std::sort_unstable        ... bench:  30,953,024 ns/iter (+/- 1,141,696)

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

test iter::sort                ... bench:   2,650,615 ns/iter (+/- 1,427,458)
test iter::sort_unstable       ... bench:   2,604,860 ns/iter (+/- 1,001,639)
test slice::sort               ... bench:   2,353,487 ns/iter (+/- 1,140,791)
test slice::sort_by_cached_key ... bench:   3,317,930 ns/iter (+/- 1,115,283)
test slice::sort_unstable      ... bench:   2,221,975 ns/iter (+/- 1,232,170)
test std::binary_heap          ... bench:   8,666,095 ns/iter (+/- 3,790,987)
test std::sort                 ... bench:  73,953,630 ns/iter (+/- 23,036,689)
test std::sort_by_cached_key   ... bench:  79,681,540 ns/iter (+/- 24,554,555)
test std::sort_unstable        ... bench:  35,327,180 ns/iter (+/- 8,306,700)

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