diff options
Diffstat (limited to 'src/corpus.rs')
| -rw-r--r-- | src/corpus.rs | 72 |
1 files changed, 31 insertions, 41 deletions
diff --git a/src/corpus.rs b/src/corpus.rs index 2fab5a4..2677cd2 100644 --- a/src/corpus.rs +++ b/src/corpus.rs @@ -51,55 +51,45 @@ impl Corpus { }); } - pub fn layout_fitness(&self, layout: &Layout) -> u32 { + pub fn prelayout_fitness(&self, layout: &Prelayout) -> u32 { let mut sfb: u32 = 0; - // TODO: We make assumptions about NUM_KEYS here - for i in 0..8 { - let ind = if i < 4 { i } else { i + 2 }; - - let k1 = layout.get_key(ind + 10 * 0); - let k2 = layout.get_key(ind + 10 * 1); - let k3 = layout.get_key(ind + 10 * 2); + for i in 0..6 { + let keys = layout.get_standard_column(i); + let k1 = keys[0]; + let k2 = keys[1]; + let k3 = keys[2]; sfb += self.bigram_count[pair_to_index(k1, k2)] + self.bigram_count[pair_to_index(k1, k3)] + self.bigram_count[pair_to_index(k2, k3)]; + } - if i == 3 { - let k4 = layout.get_key(4 + 10 * 0); - let k5 = layout.get_key(4 + 10 * 1); - let k6 = layout.get_key(4 + 10 * 2); - sfb += self.bigram_count[pair_to_index(k4, k5)] - + self.bigram_count[pair_to_index(k4, k6)] - + self.bigram_count[pair_to_index(k5, k6)] - + self.bigram_count[pair_to_index(k1, k4)] - + self.bigram_count[pair_to_index(k1, k5)] - + self.bigram_count[pair_to_index(k1, k6)] - + self.bigram_count[pair_to_index(k2, k4)] - + self.bigram_count[pair_to_index(k2, k5)] - + self.bigram_count[pair_to_index(k2, k6)] - + self.bigram_count[pair_to_index(k3, k4)] - + self.bigram_count[pair_to_index(k3, k5)] - + self.bigram_count[pair_to_index(k3, k6)]; - } else if i == 4 { - let k4 = layout.get_key(5 + 10 * 0); - let k5 = layout.get_key(5 + 10 * 1); - let k6 = layout.get_key(5 + 10 * 2); - sfb += self.bigram_count[pair_to_index(k4, k5)] - + self.bigram_count[pair_to_index(k5, k6)] - + self.bigram_count[pair_to_index(k4, k6)] - + self.bigram_count[pair_to_index(k1, k4)] - + self.bigram_count[pair_to_index(k1, k5)] - + self.bigram_count[pair_to_index(k1, k6)] - + self.bigram_count[pair_to_index(k2, k4)] - + self.bigram_count[pair_to_index(k2, k5)] - + self.bigram_count[pair_to_index(k2, k6)] - + self.bigram_count[pair_to_index(k3, k4)] - + self.bigram_count[pair_to_index(k3, k5)] - + self.bigram_count[pair_to_index(k3, k6)]; - } + for i in 0..2 { + let keys = layout.get_index_column(i); + let k1 = keys[0]; + let k2 = keys[1]; + let k3 = keys[2]; + let k4 = keys[3]; + let k5 = keys[4]; + let k6 = keys[5]; + sfb += self.bigram_count[pair_to_index(k1, k2)] + + self.bigram_count[pair_to_index(k1, k3)] + + self.bigram_count[pair_to_index(k2, k3)] + + self.bigram_count[pair_to_index(k4, k5)] + + self.bigram_count[pair_to_index(k4, k6)] + + self.bigram_count[pair_to_index(k5, k6)] + + self.bigram_count[pair_to_index(k1, k4)] + + self.bigram_count[pair_to_index(k1, k5)] + + self.bigram_count[pair_to_index(k1, k6)] + + self.bigram_count[pair_to_index(k2, k4)] + + self.bigram_count[pair_to_index(k2, k5)] + + self.bigram_count[pair_to_index(k2, k6)] + + self.bigram_count[pair_to_index(k3, k4)] + + self.bigram_count[pair_to_index(k3, k5)] + + self.bigram_count[pair_to_index(k3, k6)]; } + sfb } |
