use spellbook::Dictionary;
fn main() {
let mut args = std::env::args().skip(1);
let mode = args.next().expect("mode (check|suggest)");
let aff_path = args.next().expect("aff path");
let dic_path = args.next().expect("dic path");
let iters: u32 = args
.next()
.expect("iters")
.parse()
.expect("iters must be a number");
let words: Vec<String> = args.collect();
assert!(!words.is_empty(), "expected at least one word");
let aff = std::fs::read_to_string(&aff_path).unwrap();
let dic = std::fs::read_to_string(&dic_path).unwrap();
let dict = Dictionary::new(&aff, &dic).unwrap();
let mut total = 0usize;
match mode.as_str() {
"check" => {
for _ in 0..iters {
for word in &words {
total += dict.check(word) as usize;
}
}
}
"suggest" => {
let mut suggestions = Vec::new();
for _ in 0..iters {
for word in &words {
dict.suggest(word, &mut suggestions);
total += suggestions.len();
}
}
}
other => panic!("unknown mode {other:?}, expected `check` or `suggest`"),
}
println!(
"done ({mode}, {iters} iters, {} words): accumulator={total}",
words.len()
);
}