count

Function count 

Source
pub fn count<T>(items: &[T]) -> HashMap<T, usize>
where T: Hash + Eq + Clone,
Expand description

统计元素出现次数/Count element occurrences

§参数/Arguments

  • items - 要统计的数组/The array to count

§返回值/Returns

HashMap<T, usize> 键为元素,值为出现次数/Key is element, value is count

§示例/Examples

use slice_reducer::count;
let nums = [1, 2, 2, 3];
let counts = count(&nums);
assert_eq!(counts[&2], 2);