diff --git a/crates/dictgen/src/map.rs b/crates/dictgen/src/map.rs index 93a7d4c..711ce65 100644 --- a/crates/dictgen/src/map.rs +++ b/crates/dictgen/src/map.rs @@ -14,6 +14,7 @@ impl MapGen<'_> { data.sort_unstable_by_key(|v| unicase::UniCase::new(v.0)); let name = self.gen.name; + let key_type = "dictgen::InsensitiveStr<'static>"; let value_type = self.gen.value_type; let mut smallest = usize::MAX; @@ -44,7 +45,7 @@ impl MapGen<'_> { writeln!( file, - "pub static {name}: dictgen::Map<{value_type}> = dictgen::Map {{" + "pub static {name}: dictgen::Map<{key_type}, {value_type}> = dictgen::Map {{" )?; writeln!(file, " map: {builder},")?; writeln!(file, " range: {smallest}..={largest},")?; @@ -54,12 +55,12 @@ impl MapGen<'_> { } } -pub struct Map { - pub map: phf::Map, V>, +pub struct Map { + pub map: phf::Map, pub range: std::ops::RangeInclusive, } -impl Map { +impl Map, V> { #[inline] pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&V> { if self.range.contains(&word.len()) { @@ -69,3 +70,25 @@ impl Map { } } } + +impl Map, V> { + #[inline] + pub fn find(&self, word: &'_ unicase::Ascii<&str>) -> Option<&V> { + if self.range.contains(&word.len()) { + self.map.get(&(*word).into()) + } else { + None + } + } +} + +impl Map<&str, V> { + #[inline] + pub fn find(&self, word: &'_ &str) -> Option<&V> { + if self.range.contains(&word.len()) { + self.map.get(word) + } else { + None + } + } +} diff --git a/crates/typos-dict/benches/benches/map_codegen.rs b/crates/typos-dict/benches/benches/map_codegen.rs index 3bec624..27980c7 100644 --- a/crates/typos-dict/benches/benches/map_codegen.rs +++ b/crates/typos-dict/benches/benches/map_codegen.rs @@ -2,7 +2,7 @@ #![allow(clippy::unreadable_literal)] #![allow(unreachable_pub)] -pub static WORD: dictgen::Map<&[&str]> = dictgen::Map { +pub static WORD: dictgen::Map, &[&str]> = dictgen::Map { map: ::phf::Map { key: 12913932095322966823, disps: &[