feat: add tree-finder
This commit is contained in:
parent
1ab711f81c
commit
bdc720694f
5 changed files with 123 additions and 6 deletions
34
lib_vector_search/include/tree_finder.h
Normal file
34
lib_vector_search/include/tree_finder.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include "finder.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class SearchTreeNode {
|
||||
private:
|
||||
std::forward_list<const std::string *> words_;
|
||||
std::map<const char, SearchTreeNode> children_;
|
||||
|
||||
public:
|
||||
void insert(std::string_view partial_word, const string *original_word);
|
||||
const SearchTreeNode *find(std::string_view search_term) const;
|
||||
|
||||
std::forward_list<const std::string *> words() const;
|
||||
};
|
||||
|
||||
class SearchTree : public SearchTreeNode {
|
||||
public:
|
||||
SearchTree(const std::vector<std::string> &word_list);
|
||||
};
|
||||
|
||||
class TreeFinder : public Finder {
|
||||
private:
|
||||
SearchTree search_tree_;
|
||||
|
||||
public:
|
||||
TreeFinder(const std::vector<string> &word_list);
|
||||
|
||||
virtual std::forward_list<const std::string *>
|
||||
find_prefix(std::string_view search_term) const override;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue