data: speeded up Dictionary lookup by using another hashmap

This commit is contained in:
Eberhard Graether
2015-03-19 00:26:32 +01:00
parent 416756b1c7
commit fbd3b7ea5c
2 changed files with 6 additions and 6 deletions
+5 -6
View File
@@ -24,18 +24,17 @@ Id Dictionary::getWordId(const std::string& word)
}
m_words.emplace(++s_nextId, word);
m_ids.emplace(word, s_nextId);
return s_nextId;
}
Id Dictionary::getWordIdConst(const std::string& word) const
{
// TODO: This word lookup is very inefficient, use something smarter like a trie.
for (std::unordered_map<Id, std::string>::const_iterator it = m_words.begin(); it != m_words.end(); it++)
std::unordered_map<std::string, Id>::const_iterator it = m_ids.find(word);
if (it != m_ids.end())
{
if (it->second == word)
{
return it->first;
}
return it->second;
}
return 0;
+1
View File
@@ -31,6 +31,7 @@ private:
static Id s_nextId;
std::unordered_map<Id, std::string> m_words;
std::unordered_map<std::string, Id> m_ids; // TODO: replace id lookup to consume less momory e.g. Search Trie
std::string m_emptyWord;
};