Function lib_word_count::pivot_sort::pivot_sort_high_to_low
[-] [+]
[src]
pub fn pivot_sort_high_to_low<'a, T: Sortable>(items: &mut Vec<T>)
Sort a given vector from highest 'weight' to lowest 'weight'.
Order is derived from the return-value of weight()
.
Arguments
items
A reference to a vector containing items that implement the Sortable trait. The items will be sorted on the vector itself.
Examples
use lib_word_count::pivot_sort; // We use id to distinguish the order of objects with eual weight. let mut sort_me = vec![ Something{weight: 5, id: 1}, Something{weight: 2, id: 1}, Something{weight: 1, id: 1}, Something{weight: 3, id: 1}, Something{weight: 2, id: 2}, Something{weight: 5, id: 2}, Something{weight: 4, id: 1}, ]; pivot_sort::pivot_sort_high_to_low(&mut sort_me); assert_eq!(sort_me, vec![ Something{weight: 5, id: 1}, Something{weight: 5, id: 2}, Something{weight: 4, id: 1}, Something{weight: 3, id: 1}, Something{weight: 2, id: 1}, Something{weight: 2, id: 2}, Something{weight: 1, id: 1}, ]);