/// Creates a dictionary of digram frequencies for each pair of letters that appears in `text`
Creates a dictionary of digram frequencies for each pair of letters that appears in `text`
Creates a dictionary of digram frequencies for each pair of letters that appears in ` text `
pub fn digram(text: &[u8]) -> Result<HashMap<AsciiUppercaseDigram, usize>, errors::Error> {
    let text = common::sanitize_text(text)?;
    let mut counts = HashMap::new();
    // Note that i'm stopping iteration at the next to last character since the loop
    // uses i and i + 1
    for i in 0..(text.len() - 2) {
        let digram = (text[i], text[i + 1]);
        counts.entry(digram)
                .and_modify(|count| { *count += 1 })
                .or_insert(1usize);
    }
    Ok(counts)
}
pub fn digram ( text : & [ u8 ] ) -> Result < HashMap < AsciiUppercaseDigram , usize > , errors :: Error > { let text = common :: sanitize_text ( text ) ? ; let mut counts = HashMap :: new ( ) ; // Note that i'm stopping iteration at the next to last character since the loop // uses i and i + 1 for i in 0 .. ( text . len ( ) - 2 ) { let digram = ( text [ i ] , text [ i + 1 ] ) ; counts . entry ( digram ) . and_modify ( | count | { * count += 1 } ) . or_insert ( 1usize ) ; } Ok ( counts ) }
Creates a dictionary of digram frequencies for each pair of letters that appears in `text`
Creates a dictionary of digram frequencies for each pair of letters that appears in ` text `
text
&[u8]