Added citation
This commit is contained in:
parent
ed62663069
commit
30c0accf08
|
@ -0,0 +1,17 @@
|
||||||
|
# partial-sort
|
||||||
|
|
||||||
|
A rust implementation of [partial-sort algorithm](https://en.wikipedia.org/wiki/Partial_sorting)
|
||||||
|
based on [mesuvash's gist](https://gist.github.com/mesuvash/4095565).
|
||||||
|
|
||||||
|
### Example
|
||||||
|
``` rust
|
||||||
|
extern crate partial_sort;
|
||||||
|
use partial_sort::partial_sort;
|
||||||
|
|
||||||
|
let mut v = vec![5, 7, 4, 2, 8, 6, 1, 9, 0, 3];
|
||||||
|
partial_sort(&mut v[..], 3);
|
||||||
|
|
||||||
|
assert_eq!(v[0], 0);
|
||||||
|
assert_eq!(v[1], 1);
|
||||||
|
assert_eq!(v[2], 2);
|
||||||
|
```
|
|
@ -61,6 +61,8 @@ pub fn partial_sort_by<T, F: FnMut(&T, &T) -> Ordering>
|
||||||
/// assert_eq!(v[1], 1);
|
/// assert_eq!(v[1], 1);
|
||||||
/// assert_eq!(v[2], 2);
|
/// assert_eq!(v[2], 2);
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// The implementation is based on [this gist](https://gist.github.com/mesuvash/4095565).
|
||||||
pub fn partial_sort<T: Ord>(slice: &mut [T], k: usize) {
|
pub fn partial_sort<T: Ord>(slice: &mut [T], k: usize) {
|
||||||
partial_sort_by(slice, k as isize, &mut |x, y| x.cmp(y));
|
partial_sort_by(slice, k as isize, &mut |x, y| x.cmp(y));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue