-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrie.h
43 lines (37 loc) · 1.09 KB
/
trie.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Created by Eric on 3/9/2020.
//
#ifndef SPELLING_BEE_GEN_TRIE_H
#define SPELLING_BEE_GEN_TRIE_H
#include <unordered_map>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <pybind11/pybind11.h>
namespace py = pybind11;
class TrieNode {
private:
bool is_word;
std::unordered_map<char, TrieNode*> children;
static bool satisfies_mandatory(const std::string &word, const std::set<char> &mandatory);
void search_helper(
const std::set<char> &mandatory,
const std::set<char> &auxiliary,
std::vector<std::string> *storage,
const uint8_t depth_limit,
const std::string &word,
uint8_t depth = 1
);
public:
explicit TrieNode(bool is_word = false);
explicit TrieNode(std::vector<std::string> &v);
void add(std::string s);
bool exists(std::string s);
std::vector<std::string> search(
const std::set<char> &mandatory,
const std::set<char> &auxiliary,
const uint8_t depth_limit = 15
);
};
#endif //SPELLING_BEE_GEN_TRIE_H