Teacup rim text: Difference between revisions

m
Rust - use containers of references in find_teacup_words to avoid unnecessary copying
m (Rust - reformatted with rustfmt)
m (Rust - use containers of references in find_teacup_words to avoid unnecessary copying)
Line 1,533:
let mut dict = BTreeSet::new();
for line in io::BufReader::new(file).lines() {
if let Ok(word) = line {?;
dict.insert(word);
}
}
Ok(dict)
Line 1,541 ⟶ 1,540:
 
fn find_teacup_words(dict: &BTreeSet<String>) {
let mut teacup_words: Vec<&String> = Vec::new();
let mut found: HashSet<&String> = HashSet::new();
for word in dict {
let len = word.len();
Line 1,553 ⟶ 1,552:
for _ in 1..len {
chars.rotate_left(1);
let w =match dict.get(&String::from_iter(&chars);) {
if !dict.contains Some(&w) => {
is_teacup_word = false; if !w.eq(word) && !teacup_words.contains(&w) {
break teacup_words.push(w);
}
if !w.eq(word) && !teacup_words.contains(&w) {}
teacup_words.push(w);None => {
is_teacup_word = false;
break;
}
}
}
Line 1,566 ⟶ 1,568:
}
print!("{}", word);
found.insert(word.to_string());
for w in &teacup_words {
found.insert(w.to_string());
print!(" {}", w);
}
1,777

edits