diff options
Diffstat (limited to 'srchr/src/corpus.rs')
| -rw-r--r-- | srchr/src/corpus.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/srchr/src/corpus.rs b/srchr/src/corpus.rs index eecb122..aa6e163 100644 --- a/srchr/src/corpus.rs +++ b/srchr/src/corpus.rs @@ -18,23 +18,23 @@ const CHAR_TO_INDEX: [usize; 128] = build_lookup_table(); const NUM_BIGRAMS: usize = NUM_KEYS * NUM_KEYS; pub struct Corpus { bigram_count: [u32; NUM_BIGRAMS], - character_count: [u32; 256], + character_count: [u32; 128], total_count: u32, index_threshold: u32, } -fn pair_to_index(x: char, y: char) -> usize { +fn pair_to_index(x: u8, y: u8) -> usize { let xi = CHAR_TO_INDEX[x as usize]; let yi = CHAR_TO_INDEX[y as usize]; xi + NUM_KEYS * yi } impl Corpus { - pub fn get_character_count(&self, c: char) -> u32 { + pub fn get_character_count(&self, c: u8) -> u32 { self.character_count[c as usize] } - pub fn get_bigram_count(&self, x: char, y: char) -> u32 { + pub fn get_bigram_count(&self, x: u8, y: u8) -> u32 { self.bigram_count[pair_to_index(x, y)] } @@ -50,10 +50,10 @@ impl Corpus { let contents = fs::read_to_string(path)?; let mut bigram_count = [0; NUM_BIGRAMS]; - let mut character_count = [0; 256]; + let mut character_count = [0; 128]; let mut total_count = 0; - let mut last_char = None; + let mut last_char: Option<u8> = None; for c in contents.chars() { if let Some(c) = canonicalise(c) { if let Some(lc) = last_char { @@ -89,7 +89,7 @@ fn dump_bigrams(corpus: &Corpus) -> Vec<(String, u32)> { for &y in &KEY_CHARS[i..] { let mut pair = String::from(x); pair.push(y); - result.push((pair, corpus.bigram_count[pair_to_index(x, y)])); + result.push((pair, corpus.bigram_count[pair_to_index(x as u8, y as u8)])); } } |
