Merge pull request #238 from epage/range

fix(dict)!: Clarify word sizes with Ranges
This commit is contained in:
Ed Page authored and GitHub committed 2021-05-01 08:54:08 -05:00
commit cec850890c
5 files changed
+16 -14

No files matched your search

+6 -2
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)]
+1 -2
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;
+6 -2
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()) {
+1 -2
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"]];
+2 -6
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 {