fix(dict)!: Clarify word sizes with Ranges

The code was generated with separate min / max, rather than using a
Range and ensuring the API is used correctly.
This commit is contained in:
Ed Page 2021-04-30 21:16:04 -05:00
parent 14f1532bee
commit 6216fa0837
5 changed files with 16 additions and 14 deletions

View file

@ -38,8 +38,12 @@ fn generate<W: std::io::Write>(file: &mut W) {
writeln!(file, "{}", codegenned).unwrap();
writeln!(file, ";").unwrap();
writeln!(file).unwrap();
writeln!(file, "pub const WORD_MIN: usize = {};", smallest).unwrap();
writeln!(file, "pub const WORD_MAX: usize = {};", largest).unwrap();
writeln!(
file,
"pub const WORD_RANGE: std::ops::RangeInclusive<usize> = {}..={};",
smallest, largest
)
.unwrap();
}
#[derive(Debug, StructOpt)]

View file

@ -33649,5 +33649,4 @@ pub static WORD_DICTIONARY: phf::Map<unicase::UniCase<&'static str>, &'static st
]),
};
pub const WORD_MIN: usize = 3;
pub const WORD_MAX: usize = 19;
pub const WORD_RANGE: std::ops::RangeInclusive<usize> = 3..=19;

View file

@ -103,8 +103,12 @@ fn generate_variations<W: std::io::Write>(file: &mut W) {
writeln!(file, ";").unwrap();
writeln!(file).unwrap();
writeln!(file, "pub const WORD_MIN: usize = {};", smallest).unwrap();
writeln!(file, "pub const WORD_MAX: usize = {};", largest).unwrap();
writeln!(
file,
"pub const WORD_RANGE: std::ops::RangeInclusive<usize> = {}..={};",
smallest, largest
)
.unwrap();
for (symbol, entry) in entries.iter() {
if !referenced_symbols.contains(symbol.as_str()) {

View file

@ -113082,8 +113082,7 @@ pub static VARS_DICTIONARY: phf::Map<
]),
};
pub const WORD_MIN: usize = 2;
pub const WORD_MAX: usize = 24;
pub const WORD_RANGE: std::ops::RangeInclusive<usize> = 2..=24;
pub(crate) static ENTRY_ABETTORS_7043394254318611656: VariantsMap =
[&["abettors"], &["abetters"], &["abettors"], &["abetters"]];

View file

@ -48,9 +48,7 @@ impl BuiltIn {
// Not using `Status` to avoid the allocations
fn correct_with_dict(&self, word: &str) -> Option<&'static str> {
const WORD_RANGE: std::ops::RangeInclusive<usize> =
typos_dict::WORD_MIN..=typos_dict::WORD_MAX;
if WORD_RANGE.contains(&word.len()) {
if typos_dict::WORD_RANGE.contains(&word.len()) {
map_lookup(&typos_dict::WORD_DICTIONARY, word)
} else {
None
@ -58,9 +56,7 @@ impl BuiltIn {
}
fn correct_with_vars(&self, word: &str) -> Option<Status<'static>> {
const WORD_RANGE: std::ops::RangeInclusive<usize> =
typos_vars::WORD_MIN..=typos_vars::WORD_MAX;
if WORD_RANGE.contains(&word.len()) {
if typos_vars::WORD_RANGE.contains(&word.len()) {
map_lookup(&typos_vars::VARS_DICTIONARY, word)
.map(|variants| self.select_variant(variants))
} else {