dont allow root modifiy

This commit is contained in:
Akash Mozumdar 2019-01-27 08:49:08 -05:00
parent c596116a03
commit 69f5522492

View File

@ -14,13 +14,12 @@ struct
public: public:
void Put(std::wstring original, std::wstring replacement) void Put(std::wstring original, std::wstring replacement)
{ {
if (original.empty()) return;
Node* current = &root; Node* current = &root;
for (auto c : original) for (auto c : original)
if (Ignore(c)); if (Ignore(c));
else if (auto& next = current->next[c]) current = next.get(); else if (auto& next = current->next[c]) current = next.get();
else current = (next = std::make_unique<Node>()).get(); else current = (next = std::make_unique<Node>()).get();
current->value = replacement; if (current != &root) current->value = replacement;
} }
std::pair<int, std::wstring> Lookup(const std::wstring& text) std::pair<int, std::wstring> Lookup(const std::wstring& text)