I don't see the need for unique_ptr
for the root node.
spNode root;
I would just make this a node.
Node root;
The use of std::map
is fine. But it does have O(log(n))
lookup. If you switch back to an array its O(1)
. Its a time for space thing. Pick the one you want.
I don't like the two line creation of nodes.
std::unique_ptr<Node> node(new Node());
temp->children[c] = std::move(node);
Just use reset:
temp->children[c].reset(new Node());
Or if you have C++17C++14 use std::make_unique()
temp->children[c] = std::make_unique<Node>();
Personally search()
does not seem quite the correct verb.
bool search(const std::string& str);
What is wrong with find()
?