Merge pull request #238 from epage/range

fix(dict)!: Clarify word sizes with Ranges
This commit is contained in:
Ed Page 2021-05-01 08:54:08 -05:00 committed by GitHub
commit cec850890c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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

@ -49,9 +49,7 @@ impl BuiltIn {
#[cfg(feature = "dict")]
// 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
@ -65,9 +63,7 @@ impl BuiltIn {
#[cfg(feature = "vars")]
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 {