From 3ddc3204bb98f7e66d4544751c4e98d7e12544e1 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 4 Feb 2022 13:15:10 +1030 Subject: [PATCH] empty cache handling --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d12a06c..ab1493c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,7 +88,11 @@ fn simulate(guess: &str, solution: &str, wordcache: &HashMap } } let re = Regex::new(&re_str).unwrap(); - wordcache[&hs2str(&required_chars)].iter().filter(|w| re.is_match(w)).cloned().collect() + let cachekey = hs2str(&required_chars); + match wordcache.contains_key(&cachekey) { + true => wordcache[&cachekey].iter().filter(|w| re.is_match(w)).cloned().collect(), + false => Vec::::new(), + } } fn find_worstcase(word: &str, wordcache: &HashMap>) -> String {