Skip to content

Instantly share code, notes, and snippets.

@schmee
Created June 1, 2014 00:03
Show Gist options
  • Save schmee/c403b3ab29b178c4b4b5 to your computer and use it in GitHub Desktop.
Save schmee/c403b3ab29b178c4b4b5 to your computer and use it in GitHub Desktop.
pub fn most_common(&self, n: uint) -> Vec<(K, uint)> {
let data = self.data.clone();
let mut counted: Vec<Counted<K>> = data.move_iter().
map(|(k, v)| Counted {k: k, v: v}).collect();
let mut n_most_common = vec!();
let mut pq = PriorityQueue::from_vec(counted);
for _ in range(0u, n) {
let tmp = pq.pop().unwrap();
// error: use of partially moved value: `tmp`
let pair = (tmp.k, tmp.v);
n_most_common.push(pair);
}
n_most_common
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment