From 6d2693bc8d155a36adfde9f090dbaa7b77baaab8 Mon Sep 17 00:00:00 2001 From: JohannesGaessler Date: Thu, 8 Feb 2024 10:11:12 +0100 Subject: [PATCH] fix hashmap code --- examples/lookup-static/lookup-static.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/lookup-static/lookup-static.cpp b/examples/lookup-static/lookup-static.cpp index e3d56e49c..afdb56ebb 100644 --- a/examples/lookup-static/lookup-static.cpp +++ b/examples/lookup-static/lookup-static.cpp @@ -77,19 +77,16 @@ int main(int argc, char ** argv){ const llama_token value = inp_static[i + 2]; auto frequency_it = hashmap.find(key); - std::unordered_map frequency; if (frequency_it != hashmap.end()) { - frequency = frequency_it->second; - } - - auto token_it = frequency.find(value); - if (token_it != frequency.end()) { - token_it->second++; + auto token_it = frequency_it->second.find(value); + if (token_it != frequency_it->second.end()) { + token_it->second++; + } else { + frequency_it->second.emplace(std::make_pair(value, 1)); + } } else { + std::unordered_map frequency; frequency.emplace(std::make_pair(value, 1)); - } - - if (frequency_it == hashmap.end()) { hashmap.emplace(std::make_pair(key, frequency)); } }