/
CommandTrie.h
50 lines (38 loc) · 1.12 KB
/
CommandTrie.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
44
45
46
47
48
49
50
#ifndef COMMANDTRIE_H
#define COMMANDTRIE_H
#include <map>
class CommandTrie
{
public:
static const int NoIndex;
CommandTrie();
~CommandTrie();
bool Add(const char * command, int index, int trust);
int Lookup(const char * command, int trust) const;
private:
// Types
class Node;
typedef std::map<char, Node*> MapType;
class Node
{
public:
Node();
~Node();
MapType children;
int index;
int trust;
private:
Node(const Node &);
void operator=(const Node &);
};
// Methods
CommandTrie(const CommandTrie &); // Disable copying
void operator=(const CommandTrie &); // Disable copying
int FindLowestInChildren(const Node * node, int trust) const;
// Members
Node * m_root;
};
inline CommandTrie::CommandTrie() : m_root(new Node) {}
inline CommandTrie::~CommandTrie() {delete m_root;}
inline CommandTrie::Node::Node() : index(NoIndex), trust(0) {}
#endif