Refactor grouping count into a trait.

This commit is contained in:
2018-12-06 16:19:52 +01:00
parent d53100e591
commit c44ebaa238
4 changed files with 54 additions and 27 deletions

View File

@@ -3,16 +3,11 @@ use std::io;
use std::io::prelude::*;
use common;
use common::GroupingCount;
/// Count the occurrence characters in a string.
fn count_chars(word: &str) -> HashMap<char, u32> {
let mut counts: HashMap<char, u32> = HashMap::new();
for c in word.chars() {
*counts.entry(c).or_insert(0) += 1;
}
counts
fn count_chars(word: &str) -> HashMap<char, usize> {
word.chars().grouping_count()
}
/// Compute the number of different positions between two strings.