WordDB: use an ordered map for storing words
This way we can use lower_bound to find the first prefix match in logarithm time and we know all other prefix matches will follow.
This commit is contained in:
parent
a2c58d40b8
commit
f6eaaf1e78
|
@ -103,10 +103,11 @@ void WordDB::on_erase(const Buffer& buffer, BufferCoord begin, BufferCoord end)
|
||||||
std::vector<String> WordDB::find_prefix(const String& prefix) const
|
std::vector<String> WordDB::find_prefix(const String& prefix) const
|
||||||
{
|
{
|
||||||
std::vector<String> res;
|
std::vector<String> res;
|
||||||
for (auto& word : m_word_to_lines)
|
for (auto it = m_word_to_lines.lower_bound(prefix); it != m_word_to_lines.end(); ++it)
|
||||||
{
|
{
|
||||||
if (prefix_match(word.first, prefix))
|
if (not prefix_match(it->first, prefix))
|
||||||
res.push_back(word.first);
|
break;
|
||||||
|
res.push_back(it->first);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
std::vector<String> find_prefix(const String& prefix) const;
|
std::vector<String> find_prefix(const String& prefix) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using WordToLines = std::unordered_map<String, std::vector<LineCount>>;
|
using WordToLines = std::map<String, std::vector<LineCount>>;
|
||||||
using LineToWords = std::map<LineCount, std::vector<String>>;
|
using LineToWords = std::map<LineCount, std::vector<String>>;
|
||||||
|
|
||||||
void add_words(LineCount line, const String& content);
|
void add_words(LineCount line, const String& content);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user