-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtrie.h
65 lines (59 loc) · 1.14 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef __TRIE_H__
#define __TRIE_H__
#include<vector>
#include<list>
#include<string>
#include<iostream>
struct node;
struct subnode{
subnode(){
value = -1;
ptr = NULL;
}
~subnode(){
ptr = NULL;
}
subnode& operator = ( subnode& );
unsigned int value;
struct node* ptr;
};
struct dnode{
dnode(){
}
void add( const std::string& str ){
m_d.push_back( str );
#ifdef DEBUG2
std::cout << "dnode::add data size : " << m_d.size() << "\n";
#endif
}
std::vector<std::string> m_d;
};
struct node{
public:
node();
~node();
node* query( const unsigned int key );
node* add_child( unsigned int key );
void add_data( const std::string& data );
void copy_data( dnode& );
bool data();
private:
bool m_bdata;
struct subnode* m_child;
struct dnode* m_data;
int m_cnt;
int m_size;
void init_child();
void enlarge();
};
class trie {
public:
trie();
~trie();
void add(const std::vector<unsigned int>& key,const std::string& value );
bool query(const std::vector<unsigned int>& key, dnode& data );
bool query(const std::vector<unsigned int>& key );
private:
node m_root;
};
#endif // __TRIE_H__