2024-03-20 14:05:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "finder.h"
|
2024-03-21 07:55:44 +00:00
|
|
|
#include "word_list.h"
|
2024-03-20 14:05:25 +00:00
|
|
|
|
2024-03-22 14:37:13 +00:00
|
|
|
#include <unordered_map>
|
2024-03-20 14:05:25 +00:00
|
|
|
|
|
|
|
class SearchTreeNode {
|
|
|
|
private:
|
2024-03-21 19:16:00 +00:00
|
|
|
WordRefList words_;
|
2024-03-23 12:43:58 +00:00
|
|
|
std::unordered_map<char, SearchTreeNode *> children_;
|
2024-03-20 14:05:25 +00:00
|
|
|
|
|
|
|
public:
|
2024-03-23 12:43:58 +00:00
|
|
|
~SearchTreeNode();
|
|
|
|
|
2024-03-20 19:51:16 +00:00
|
|
|
void insert(std::string_view partial_word, const std::string *original_word);
|
2024-03-20 14:05:25 +00:00
|
|
|
const SearchTreeNode *find(std::string_view search_term) const;
|
|
|
|
|
2024-03-21 19:16:00 +00:00
|
|
|
WordRefList words() const;
|
2024-03-20 14:05:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SearchTree : public SearchTreeNode {
|
|
|
|
public:
|
2024-03-21 07:55:44 +00:00
|
|
|
SearchTree(const WordList &word_list);
|
2024-03-20 14:05:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TreeFinder : public Finder {
|
|
|
|
private:
|
|
|
|
SearchTree search_tree_;
|
|
|
|
|
|
|
|
public:
|
2024-03-21 07:55:44 +00:00
|
|
|
TreeFinder(const WordList &word_list);
|
2024-03-20 14:05:25 +00:00
|
|
|
|
2024-03-21 19:16:00 +00:00
|
|
|
WordRefList find_prefix(std::string_view search_term) const override;
|
2024-03-20 14:05:25 +00:00
|
|
|
};
|