From 19e4b5bead91b3c5eaefec77d5f703df9c1b2305 Mon Sep 17 00:00:00 2001 From: tslil clingman Date: Tue, 27 Sep 2022 00:27:37 +0200 Subject: Penalty for index under-usage --- src/layout.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'src/layout.rs') diff --git a/src/layout.rs b/src/layout.rs index 2650a51..bc476c8 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -22,7 +22,7 @@ impl Prelayout { let mut standard_columns = pl.standard_columns.clone(); let mut index_columns = pl.index_columns.clone(); - let mut count = rng.gen_range(1..=NUM_KEYS - 1); + let mut count = rng.gen_range(1..NUM_KEYS); while count > 0 { let source_index: bool = rng.gen(); let target_index: bool = rng.gen(); @@ -120,8 +120,6 @@ impl Prelayout { #[derive(Copy, Clone)] pub struct Layout { keys: [char; NUM_KEYS], - // index in KEY_CHAR -> index in layout - translate_index: [usize; NUM_KEYS], } impl Layout { @@ -134,31 +132,22 @@ impl Layout { Layout::char_array_to_layout(pl.to_char_array()) } - fn char_array_to_layout(layout: [char; NUM_KEYS]) -> Layout { - let mut translate_index: [usize; NUM_KEYS] = [0; NUM_KEYS]; - - for (i, seek) in KEY_CHARS.iter().enumerate() { - for (j, found) in layout.iter().enumerate() { - if seek == found { - translate_index[i] = j; - } - } + pub fn get_index(&self, c: char) -> usize { + let mut found_key = 0; + while self.keys[found_key] != c { + found_key += 1 } + found_key + } - return Layout { - keys: layout, - translate_index, - }; + fn char_array_to_layout(keys: [char; NUM_KEYS]) -> Layout { + return Layout { keys }; } pub fn get_key(&self, index: usize) -> char { self.keys[index] } - pub fn translate_index(&self, i: usize) -> usize { - self.translate_index[i] - } - pub fn from_verbose(inp: &str) -> Option { let mut layout: [char; NUM_KEYS] = ['x'; NUM_KEYS]; -- cgit v1.3.1