refactor: backport to MinGW 11
parent
1441a869c2
commit
961a6bdf6c
|
@ -8,9 +8,11 @@
|
|||
class SearchTreeNode {
|
||||
private:
|
||||
WordRefList words_;
|
||||
std::unordered_map<char, SearchTreeNode> children_;
|
||||
std::unordered_map<char, SearchTreeNode *> children_;
|
||||
|
||||
public:
|
||||
~SearchTreeNode();
|
||||
|
||||
void insert(std::string_view partial_word, const std::string *original_word);
|
||||
const SearchTreeNode *find(std::string_view search_term) const;
|
||||
|
||||
|
|
|
@ -2,12 +2,22 @@
|
|||
|
||||
using std::string, std::string_view;
|
||||
|
||||
SearchTreeNode::~SearchTreeNode() {
|
||||
for (auto [_, child] : children_) {
|
||||
delete child;
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTreeNode::insert(string_view partial_word,
|
||||
const string *original_word) {
|
||||
if (partial_word.empty()) {
|
||||
words_.push_back(original_word);
|
||||
} else {
|
||||
children_[partial_word.front()].insert(
|
||||
const auto &initial = partial_word.front();
|
||||
if (!children_.contains(initial)) {
|
||||
children_.insert({initial, new SearchTreeNode});
|
||||
}
|
||||
children_[partial_word.front()]->insert(
|
||||
string_view(partial_word).substr(1, partial_word.length()),
|
||||
original_word);
|
||||
}
|
||||
|
@ -20,7 +30,7 @@ const SearchTreeNode *SearchTreeNode::find(string_view search_term) const {
|
|||
|
||||
auto child = children_.find(search_term.front());
|
||||
if (child != children_.cend()) {
|
||||
return child->second.find(search_term.substr(1, search_term.length()));
|
||||
return child->second->find(search_term.substr(1, search_term.length()));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -29,7 +39,7 @@ const SearchTreeNode *SearchTreeNode::find(string_view search_term) const {
|
|||
WordRefList SearchTreeNode::words() const {
|
||||
WordRefList results(words_);
|
||||
for (const auto &child : children_) {
|
||||
auto child_words = child.second.words();
|
||||
auto child_words = child.second->words();
|
||||
std::move(child_words.begin(), child_words.end(),
|
||||
std::back_inserter(results));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue