diff options
| author | tslil clingman <tslil@posteo.de> | 2022-09-29 22:55:01 +0200 |
|---|---|---|
| committer | tslil clingman <tslil@posteo.de> | 2022-09-29 22:55:01 +0200 |
| commit | ab985ecb4cb6bcc8a65ff79aa746a1f80fa4b2f4 (patch) | |
| tree | 876352f82e51723ac1cbadeda272c3adbef00ae5 /srchr/src/config.rs | |
| parent | 785fa20b4e4a5372857f6f033b9d478685460cea (diff) | |
Refactor code
Diffstat (limited to 'srchr/src/config.rs')
| -rw-r--r-- | srchr/src/config.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/srchr/src/config.rs b/srchr/src/config.rs new file mode 100644 index 0000000..99afa4c --- /dev/null +++ b/srchr/src/config.rs @@ -0,0 +1,47 @@ +// Search parameters +pub const CORPUS_FILE_NAME: &str = "corpus.txt"; + +pub const STARTING_LAYOUT_STRING: &str = " +Q W E R T Y U I O P +A S D F G H J K L ' +Z X C V B N M , . / +"; + +pub const NUM_CONTESTANTS: usize = 128; +pub const NUM_PERSIST: usize = 8; + +pub const DESIRED_INDEX_USAGE_PERCENT: f32 = 0.15; +pub const fn index_usage_fitness(index_threshold: u32, index_count: u32) -> u32 { + (index_threshold as i64 - index_count as i64).abs() as u32 / 64 +} + +// Do not change, code makes assumptions about these +pub const NUM_KEYS: usize = 30; +pub const ROW_LENGTH: usize = 10; + +pub const KEY_CHARS: [char; NUM_KEYS] = [ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '/', '.', ',', '\'', +]; + +pub const KEY_TO_FINGER: [usize; NUM_KEYS] = [ + 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, 0, 1, 2, 3, 3, 4, 4, 5, 6, 7, +]; + +pub fn canonicalise(inp: char) -> Option<char> { + if inp.is_ascii_alphabetic() { + return Some(inp.to_ascii_uppercase()); + } else { + match inp { + '.' => Some('.'), + '>' => Some('.'), + ',' => Some(','), + '<' => Some(','), + '/' => Some('/'), + '?' => Some('/'), + '\'' => Some('\''), + '"' => Some('\''), + _ => None, + } + } +} |
