Merge pull request #1197 from epage/rename
Some checks are pending
Security audit / security_audit (push) Waiting to run
Security audit / cargo_deny (bans licenses sources) (push) Waiting to run
CI / CI (push) Blocked by required conditions
CI / Test (push) Waiting to run
CI / Check MSRV (push) Waiting to run
CI / lockfile (push) Waiting to run
CI / Docs (push) Waiting to run
CI / rustfmt (push) Waiting to run
CI / clippy (push) Waiting to run
CI / Coverage (push) Waiting to run
/ linux (aarch64) (push) Waiting to run
/ linux (x86) (push) Waiting to run
/ linux (x86_64) (push) Waiting to run
/ musllinux (aarch64) (push) Waiting to run
/ musllinux (x86_64) (push) Waiting to run
/ windows (x64) (push) Waiting to run
/ windows (x86) (push) Waiting to run
/ macos (aarch64) (push) Waiting to run
/ macos (x86_64) (push) Waiting to run
/ sdist (push) Waiting to run
/ Release (push) Blocked by required conditions
pre-commit / pre-commit (push) Waiting to run

fix(dictgen): Clarify names
This commit is contained in:
Ed Page 2024-12-30 15:11:50 -06:00 committed by GitHub
commit 086f9d1558
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: B5690EEEBB952194
18 changed files with 44136 additions and 44136 deletions

View file

@ -1,6 +1,6 @@
// This file is @generated crates/codespell-dict/tests/codegen.rs
pub static WORD_DICTIONARY: dictgen::DictTable<&[&str]> = dictgen::DictTable {
pub static WORD_DICTIONARY: dictgen::OrderedMap<&[&str]> = dictgen::OrderedMap {
keys: &[
dictgen::InsensitiveStr::Ascii("1nd"),
dictgen::InsensitiveStr::Ascii("2rd"),

View file

@ -54,7 +54,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
dictgen::DictGen::new()
.name("WORD_DICTIONARY")
.value_type("&[&str]")
.table()
.ordered_map()
.write(file, dict.map(|kv| (kv.0, format!("&{:?}", kv.1))))
.unwrap();
}

View file

@ -35,16 +35,16 @@ impl<'g> DictGen<'g> {
}
#[cfg(feature = "map")]
pub fn map(self) -> crate::DictMapGen<'g> {
crate::DictMapGen { gen: self }
pub fn map(self) -> crate::MapGen<'g> {
crate::MapGen { gen: self }
}
pub fn table(self) -> crate::DictTableGen<'g> {
crate::DictTableGen { gen: self }
pub fn ordered_map(self) -> crate::OrderedMapGen<'g> {
crate::OrderedMapGen { gen: self }
}
pub fn trie(self) -> crate::DictTrieGen<'g> {
crate::DictTrieGen {
pub fn trie(self) -> crate::TrieGen<'g> {
crate::TrieGen {
gen: self,
limit: 64,
}

View file

@ -7,7 +7,7 @@ mod gen;
mod insensitive;
#[cfg(feature = "map")]
mod map;
mod table;
mod ordered_map;
mod trie;
#[cfg(feature = "codegen")]
@ -15,5 +15,5 @@ pub use gen::*;
pub use insensitive::*;
#[cfg(feature = "map")]
pub use map::*;
pub use table::*;
pub use ordered_map::*;
pub use trie::*;

View file

@ -1,10 +1,10 @@
#[cfg(feature = "codegen")]
pub struct DictMapGen<'g> {
pub struct MapGen<'g> {
pub(crate) gen: crate::DictGen<'g>,
}
#[cfg(feature = "codegen")]
impl DictMapGen<'_> {
impl MapGen<'_> {
pub fn write<'d, W: std::io::Write, V: std::fmt::Display>(
&self,
file: &mut W,
@ -44,7 +44,7 @@ impl DictMapGen<'_> {
writeln!(
file,
"pub static {name}: dictgen::DictMap<{value_type}> = dictgen::DictMap {{"
"pub static {name}: dictgen::Map<{value_type}> = dictgen::Map {{"
)?;
writeln!(file, " map: {builder},")?;
writeln!(file, " range: {smallest}..={largest},")?;
@ -54,12 +54,12 @@ impl DictMapGen<'_> {
}
}
pub struct DictMap<V: 'static> {
pub struct Map<V: 'static> {
pub map: phf::Map<crate::InsensitiveStr<'static>, V>,
pub range: std::ops::RangeInclusive<usize>,
}
impl<V> DictMap<V> {
impl<V> Map<V> {
#[inline]
pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&V> {
if self.range.contains(&word.len()) {

View file

@ -1,10 +1,10 @@
#[cfg(feature = "codegen")]
pub struct DictTableGen<'g> {
pub struct OrderedMapGen<'g> {
pub(crate) gen: crate::DictGen<'g>,
}
#[cfg(feature = "codegen")]
impl DictTableGen<'_> {
impl OrderedMapGen<'_> {
pub fn write<'d, W: std::io::Write, V: std::fmt::Display>(
&self,
file: &mut W,
@ -21,7 +21,7 @@ impl DictTableGen<'_> {
writeln!(
file,
"pub static {name}: dictgen::DictTable<{value_type}> = dictgen::DictTable {{"
"pub static {name}: dictgen::OrderedMap<{value_type}> = dictgen::OrderedMap {{"
)?;
writeln!(file, " keys: &[")?;
for (key, _value) in data.iter() {
@ -52,13 +52,13 @@ impl DictTableGen<'_> {
}
}
pub struct DictTable<V: 'static> {
pub struct OrderedMap<V: 'static> {
pub keys: &'static [crate::InsensitiveStr<'static>],
pub values: &'static [V],
pub range: core::ops::RangeInclusive<usize>,
}
impl<V> DictTable<V> {
impl<V> OrderedMap<V> {
#[inline]
pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&'static V> {
if self.range.contains(&word.len()) {

View file

@ -1,11 +1,11 @@
#[cfg(feature = "codegen")]
pub struct DictTrieGen<'g> {
pub struct TrieGen<'g> {
pub(crate) gen: crate::DictGen<'g>,
pub(crate) limit: usize,
}
#[cfg(feature = "codegen")]
impl DictTrieGen<'_> {
impl TrieGen<'_> {
pub fn limit(mut self, limit: usize) -> Self {
self.limit = limit;
self
@ -25,13 +25,13 @@ impl DictTrieGen<'_> {
}
}
pub struct DictTrie<V: 'static> {
pub root: &'static DictTrieNode<V>,
pub unicode: &'static crate::DictTable<V>,
pub struct Trie<V: 'static> {
pub root: &'static TrieNode<V>,
pub unicode: &'static crate::OrderedMap<V>,
pub range: core::ops::RangeInclusive<usize>,
}
impl<V> DictTrie<V> {
impl<V> Trie<V> {
#[inline]
pub fn find(&self, word: &'_ unicase::UniCase<&str>) -> Option<&'static V> {
if word
@ -54,7 +54,7 @@ impl<V> DictTrie<V> {
let mut child = &self.root;
for i in 0..word.len() {
match child.children {
DictTrieChild::Nested(n) => {
TrieChild::Nested(n) => {
let byte = word[i];
let index = if byte.is_ascii_lowercase() {
byte - b'a'
@ -70,7 +70,7 @@ impl<V> DictTrie<V> {
return None;
}
}
DictTrieChild::Flat(t) => {
TrieChild::Flat(t) => {
let remaining = &word[i..word.len()];
// Unsafe: Everything before has been proven to be ASCII, so this should be
// safe.
@ -84,14 +84,14 @@ impl<V> DictTrie<V> {
}
}
pub struct DictTrieNode<V: 'static> {
pub children: DictTrieChild<V>,
pub struct TrieNode<V: 'static> {
pub children: TrieChild<V>,
pub value: Option<V>,
}
pub enum DictTrieChild<V: 'static> {
Nested(&'static [Option<&'static DictTrieNode<V>>; 26]),
Flat(&'static crate::DictTable<V>),
pub enum TrieChild<V: 'static> {
Nested(&'static [Option<&'static TrieNode<V>>; 26]),
Flat(&'static crate::OrderedMap<V>),
}
#[cfg(feature = "codegen")]
@ -110,7 +110,7 @@ mod codegen {
writeln!(
file,
"pub static {name}: dictgen::DictTrie<{value_type}> = dictgen::DictTrie {{"
"pub static {name}: dictgen::Trie<{value_type}> = dictgen::Trie {{"
)?;
writeln!(file, " root: &{},", gen_node_name(name, ""))?;
writeln!(file, " unicode: &{},", &unicode_table_name)?;
@ -126,7 +126,7 @@ mod codegen {
crate::DictGen::new()
.name(&unicode_table_name)
.value_type(value_type)
.table()
.ordered_map()
.write(file, root.unicode.into_iter())?;
writeln!(file)?;
@ -136,7 +136,7 @@ mod codegen {
let children_name = gen_children_name(name, &start);
writeln!(
file,
"static {node_name}: dictgen::DictTrieNode<{value_type}> = dictgen::DictTrieNode {{"
"static {node_name}: dictgen::TrieNode<{value_type}> = dictgen::TrieNode {{"
)?;
writeln!(
file,
@ -156,7 +156,7 @@ mod codegen {
DynChild::Nested(n) => {
writeln!(
file,
"static {children_name}: [Option<&dictgen::DictTrieNode<{value_type}>>; 26] = [",
"static {children_name}: [Option<&dictgen::TrieNode<{value_type}>>; 26] = [",
)?;
for b in b'a'..=b'z' {
if let Some(child) = n.get(&b) {
@ -178,7 +178,7 @@ mod codegen {
crate::DictGen::new()
.name(&children_name)
.value_type(value_type)
.table()
.ordered_map()
.write(file, table_input)?;
}
}
@ -211,8 +211,8 @@ mod codegen {
fn gen_type_name<V>(leaf: &DynChild<'_, V>) -> &'static str {
match leaf {
DynChild::Nested(_) => "dictgen::DictTrieChild::Nested",
DynChild::Flat(_) => "dictgen::DictTrieChild::Flat",
DynChild::Nested(_) => "dictgen::TrieChild::Nested",
DynChild::Flat(_) => "dictgen::TrieChild::Flat",
}
}

View file

@ -1,6 +1,6 @@
// This file is @generated by crates/misspell-dict/tests/codegen.rs
pub static MAIN_DICTIONARY: dictgen::DictTable<&[&str]> = dictgen::DictTable {
pub static MAIN_DICTIONARY: dictgen::OrderedMap<&[&str]> = dictgen::OrderedMap {
keys: &[
dictgen::InsensitiveStr::Ascii("abandenment"),
dictgen::InsensitiveStr::Ascii("abandining"),
@ -56101,7 +56101,7 @@ pub static MAIN_DICTIONARY: dictgen::DictTable<&[&str]> = dictgen::DictTable {
],
range: 3..=19,
};
pub static AMERICAN_DICTIONARY: dictgen::DictTable<&[&str]> = dictgen::DictTable {
pub static AMERICAN_DICTIONARY: dictgen::OrderedMap<&[&str]> = dictgen::OrderedMap {
keys: &[
dictgen::InsensitiveStr::Ascii("accessorise"),
dictgen::InsensitiveStr::Ascii("accessorised"),
@ -59346,7 +59346,7 @@ pub static AMERICAN_DICTIONARY: dictgen::DictTable<&[&str]> = dictgen::DictTable
],
range: 4..=20,
};
pub static BRITISH_DICTIONARY: dictgen::DictTable<&[&str]> = dictgen::DictTable {
pub static BRITISH_DICTIONARY: dictgen::OrderedMap<&[&str]> = dictgen::OrderedMap {
keys: &[
dictgen::InsensitiveStr::Ascii("accessorize"),
dictgen::InsensitiveStr::Ascii("accessorized"),

View file

@ -30,7 +30,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
dictgen::DictGen::new()
.name("MAIN_DICTIONARY")
.value_type("&[&str]")
.table()
.ordered_map()
.write(
file,
main.into_iter().map(|kv| (kv.0, format!("&{:?}", kv.1))),
@ -40,7 +40,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
dictgen::DictGen::new()
.name("AMERICAN_DICTIONARY")
.value_type("&[&str]")
.table()
.ordered_map()
.write(
file,
american
@ -52,7 +52,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
dictgen::DictGen::new()
.name("BRITISH_DICTIONARY")
.value_type("&[&str]")
.table()
.ordered_map()
.write(
file,
british.into_iter().map(|kv| (kv.0, format!("&{:?}", kv.1))),

View file

@ -1,7 +1,7 @@
#![allow(clippy::wildcard_imports)]
mod map_codegen;
mod table_codegen;
mod ordered_map_codegen;
mod trie_codegen;
mod miss {
@ -20,8 +20,8 @@ mod miss {
}
#[divan::bench(args = [unicase::UniCase::new(MISS)])]
fn table(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
table_codegen::WORD.find(&word)
fn ordered_map(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
ordered_map_codegen::WORD.find(&word)
}
}
@ -41,8 +41,8 @@ mod hit {
}
#[divan::bench(args = [unicase::UniCase::new(HIT)])]
fn table(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
table_codegen::WORD.find(&word)
fn ordered_map(word: unicase::UniCase<&str>) -> Option<&'static &[&str]> {
ordered_map_codegen::WORD.find(&word)
}
}

View file

@ -2,7 +2,7 @@
#![allow(clippy::unreadable_literal)]
#![allow(unreachable_pub)]
pub static WORD: dictgen::DictMap<&[&str]> = dictgen::DictMap {
pub static WORD: dictgen::Map<&[&str]> = dictgen::Map {
map: ::phf::Map {
key: 12913932095322966823,
disps: &[

View file

@ -2,7 +2,7 @@
#![allow(clippy::unreadable_literal)]
#![allow(unreachable_pub)]
pub static WORD: dictgen::DictTable<&[&str]> = dictgen::DictTable {
pub static WORD: dictgen::OrderedMap<&[&str]> = dictgen::OrderedMap {
keys: &[
dictgen::InsensitiveStr::Ascii("aaccess"),
dictgen::InsensitiveStr::Ascii("aaccessibility"),

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -20,13 +20,13 @@ fn codegen() {
snapbox::file!["../benches/benches/map_codegen.rs"].raw()
);
let mut table_content = vec![];
generate_table(&mut table_content, "WORD", DICT);
let table_content = String::from_utf8(table_content).unwrap();
let table_content = codegenrs::rustfmt(&table_content, None).unwrap();
let mut ordered_map_content = vec![];
generate_ordered_map(&mut ordered_map_content, "WORD", DICT);
let ordered_map_content = String::from_utf8(ordered_map_content).unwrap();
let ordered_map_content = codegenrs::rustfmt(&ordered_map_content, None).unwrap();
snapbox::assert_data_eq!(
&table_content,
snapbox::file!["../benches/benches/table_codegen.rs"].raw()
&ordered_map_content,
snapbox::file!["../benches/benches/ordered_map_codegen.rs"].raw()
);
snapbox::assert_data_eq!(
@ -109,7 +109,7 @@ fn generate_map<W: std::io::Write>(file: &mut W, name: &str, dict: &[u8]) {
.unwrap();
}
fn generate_table<W: std::io::Write>(file: &mut W, name: &str, dict: &[u8]) {
fn generate_ordered_map<W: std::io::Write>(file: &mut W, name: &str, dict: &[u8]) {
writeln!(
file,
"// This file is @generated by {}",
@ -130,7 +130,7 @@ fn generate_table<W: std::io::Write>(file: &mut W, name: &str, dict: &[u8]) {
dictgen::DictGen::new()
.name(name)
.value_type("&[&str]")
.table()
.ordered_map()
.write(
file,
records.iter().map(|record| {

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
// This file is @generated by crates/wikipedia-dict/tests/codegen.rs
pub static WORD_DICTIONARY: dictgen::DictTable<&[&str]> = dictgen::DictTable {
pub static WORD_DICTIONARY: dictgen::OrderedMap<&[&str]> = dictgen::OrderedMap {
keys: &[
dictgen::InsensitiveStr::Ascii("abandonned"),
dictgen::InsensitiveStr::Ascii("abbout"),

View file

@ -24,7 +24,7 @@ fn generate<W: std::io::Write>(file: &mut W) {
dictgen::DictGen::new()
.name("WORD_DICTIONARY")
.value_type("&[&str]")
.table()
.ordered_map()
.write(file, dict.map(|kv| (kv.0, format!("&{:?}", kv.1))))
.unwrap();
}