data: speeded up Dictionary lookup by using another hashmap
This commit is contained in:
@@ -24,18 +24,17 @@ Id Dictionary::getWordId(const std::string& word)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_words.emplace(++s_nextId, word);
|
m_words.emplace(++s_nextId, word);
|
||||||
|
m_ids.emplace(word, s_nextId);
|
||||||
return s_nextId;
|
return s_nextId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Dictionary::getWordIdConst(const std::string& word) const
|
Id Dictionary::getWordIdConst(const std::string& word) const
|
||||||
{
|
{
|
||||||
// TODO: This word lookup is very inefficient, use something smarter like a trie.
|
std::unordered_map<std::string, Id>::const_iterator it = m_ids.find(word);
|
||||||
for (std::unordered_map<Id, std::string>::const_iterator it = m_words.begin(); it != m_words.end(); it++)
|
|
||||||
|
if (it != m_ids.end())
|
||||||
{
|
{
|
||||||
if (it->second == word)
|
return it->second;
|
||||||
{
|
|
||||||
return it->first;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ private:
|
|||||||
static Id s_nextId;
|
static Id s_nextId;
|
||||||
|
|
||||||
std::unordered_map<Id, std::string> m_words;
|
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;
|
std::string m_emptyWord;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user