-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
radix_tree_node.hpp
56 lines (46 loc) · 1.63 KB
/
radix_tree_node.hpp
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
#ifndef RADIX_TREE_NODE_HPP
#define RADIX_TREE_NODE_HPP
#include <map>
#include <functional>
template <typename K, typename T, typename Compare>
class radix_tree_node {
friend class radix_tree<K, T, Compare>;
friend class radix_tree_it<K, T, Compare>;
typedef std::pair<const K, T> value_type;
typedef typename std::map<K, radix_tree_node<K, T, Compare>*, Compare >::iterator it_child;
private:
radix_tree_node(Compare& pred) : m_children(std::map<K, radix_tree_node<K, T, Compare>*, Compare>(pred)), m_parent(NULL), m_value(NULL), m_depth(0), m_is_leaf(false), m_key(), m_pred(pred) { }
radix_tree_node(const value_type &val, Compare& pred);
radix_tree_node(const radix_tree_node&); // delete
radix_tree_node& operator=(const radix_tree_node&); // delete
~radix_tree_node();
std::map<K, radix_tree_node<K, T, Compare>*, Compare> m_children;
radix_tree_node<K, T, Compare> *m_parent;
value_type *m_value;
int m_depth;
bool m_is_leaf;
K m_key;
Compare& m_pred;
};
template <typename K, typename T, typename Compare>
radix_tree_node<K, T, Compare>::radix_tree_node(const value_type &val, Compare& pred) :
m_children(std::map<K, radix_tree_node<K, T, Compare>*, Compare>(pred)),
m_parent(NULL),
m_value(NULL),
m_depth(0),
m_is_leaf(false),
m_key(),
m_pred(pred)
{
m_value = new value_type(val);
}
template <typename K, typename T, typename Compare>
radix_tree_node<K, T, Compare>::~radix_tree_node()
{
it_child it;
for (it = m_children.begin(); it != m_children.end(); ++it) {
delete it->second;
}
delete m_value;
}
#endif // RADIX_TREE_NODE_HPP