Added citation

This commit is contained in:
Thomas Forgione 2018-07-09 16:38:47 +02:00
parent ed62663069
commit 30c0accf08
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
2 changed files with 19 additions and 0 deletions

17
src/README.md Normal file
View File

@ -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);
```

View File

@ -61,6 +61,8 @@ pub fn partial_sort_by<T, F: FnMut(&T, &T) -> Ordering>
/// assert_eq!(v[1], 1);
/// 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) {
partial_sort_by(slice, k as isize, &mut |x, y| x.cmp(y));
}