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

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},
]);