handling fallout from entry api

This commit is contained in:
Alexis Beingessner
2014-09-18 17:05:52 -04:00
parent 8e58f3088b
commit fe8a413fc0
14 changed files with 99 additions and 44 deletions

View File

@@ -11,6 +11,7 @@
#![allow(missing_doc)]
use std::collections::hashmap;
use std::collections::hashmap::{Occupied, Vacant};
use std::fmt::Show;
use std::hash::Hash;
use std::io;
@@ -443,7 +444,10 @@ pub fn write_boxplot<T: Float + Show + FromPrimitive>(
pub fn freq_count<T: Iterator<U>, U: Eq+Hash>(mut iter: T) -> hashmap::HashMap<U, uint> {
let mut map: hashmap::HashMap<U,uint> = hashmap::HashMap::new();
for elem in iter {
map.insert_or_update_with(elem, 1, |_, count| *count += 1);
match map.entry(elem) {
Occupied(mut entry) => { *entry.get_mut() += 1; },
Vacant(entry) => { entry.set(1); },
}
}
map
}