-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdouble_array_trie.h
More file actions
44 lines (41 loc) · 1.32 KB
/
Copy pathdouble_array_trie.h
File metadata and controls
44 lines (41 loc) · 1.32 KB
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
44
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
using namespace std;
struct BaseItem {
int val;
set<char> out;
bool isLeaf;
list<char>::iterator tail;
BaseItem(list<char> &tail_list): val(0), isLeaf(false), tail(tail_list.end()) {}
};
#ifndef DOUBLE_ARRAY_TRIE_H
#define DOUBLE_ARRAY_TRIE_H
class DoubleArrayTrie {
private:
bool ignore_case;
list<char> tail_array;
vector<int> check_array;
vector<BaseItem> base_array;
map<char, int> dict;
bool isLegalStr(const string &str);
void storeTailHead(int index, char item);
void insertTailArray(int index, const string &str, int str_index);
void resolvePrefixConflict(int index, const string& str, int str_index);
void resolveBaseConflict(int pre_index, int old_base_index, int check_index, int str_index, const string& str);
int getNewBase(int cur_index, char s);
void getNewBase(int cur_index, char s, bool isAdded);
void getNewBase(int cur_index, char s1, char s2, int &prefix1_index, int &prefix2_index);
bool compareStr(int str_index, const string& str, int index);
void clearCheckAndBase(const string& str, int str_index, int index);
public:
DoubleArrayTrie(bool igore_case = true);
bool findStr(const string &str);
void insertStr(const string &str);
void deleteStr(const string &str);
bool isEmptyTail();
bool isEmptyTrie();
};
#endif