Aleph-w
1.5a.2
Biblioteca general de algoritmos y estructuras de datos
Todo
Clases
Archivos
Funciones
Variables
'typedefs'
Enumeraciones
Amigas
Grupos
Páginas
tpl_binNode.H
Ir a la documentación de este archivo.
1
# ifndef TPL_BINNODE_H
2
# define TPL_BINNODE_H
3
4
# include <iostream>
5
# include <ahDefs.H>
6
# include <ahAssert.H>
7
8
namespace
Aleph {
9
10
11
struct
Empty_Node
12
{
13
Empty_Node
() {
/* empty */
}
14
15
Empty_Node
(SentinelCtor) {
/* empty */
}
16
17
void
reset() {
/* empty */
}
18
19
Empty_Node
& get_data()
20
{
21
throw
std::domain_error(
"Empty_Node has not data"
);
22
}
23
};
24
25
# define INIT_CLASS_BINNODE(Name, height, Control_Data) \
26
template <typename Key> \
27
class Name : public Control_Data \
28
{ \
29
public: \
30
static const size_t MaxHeight = height; \
31
static Name * const NullPtr; \
32
typedef Key key_type; \
33
typedef Key Key_Type; \
34
\
35
private: \
36
\
37
Key key; \
38
Name * lLink; \
39
Name * rLink; \
40
\
41
public: \
42
\
43
Key & get_key() { return key; } \
44
const Key & get_key() const { return key; } \
45
Name *& getL() { return lLink; } \
46
Name *& getR() { return rLink; } \
47
Name(const Key& k) : key(k), lLink(NullPtr), rLink(NullPtr) \
48
{ \
49
/* Empty */
\
50
} \
51
Name(Key && k) \
52
: lLink(NullPtr), rLink(NullPtr) \
53
{ \
54
std::swap(key, k); \
55
} \
56
Name(const Control_Data & control_data, const Key & k) : \
57
Control_Data(control_data), \
58
key(k), lLink(NullPtr), rLink(NullPtr) \
59
{ \
60
/* Empty */
\
61
} \
62
Name(const Name & node) : \
63
Control_Data(node), \
64
key(node.key), lLink(NullPtr), rLink(NullPtr) \
65
{ \
66
/* Empty */
\
67
} \
68
Name(Name && node) : \
69
Control_Data(std::move(node)), \
70
key(std::move(node).key), lLink(NullPtr), rLink(NullPtr) \
71
{ \
72
/* Empty */
\
73
} \
74
Name(const Control_Data & control_data) : \
75
Control_Data(control_data), \
76
lLink(NullPtr), rLink(NullPtr) \
77
{ \
78
/* Empty */
\
79
} \
80
Name() : lLink(NullPtr), rLink(NullPtr) \
81
{ \
82
/* Empty */
\
83
} \
84
void reset() \
85
{ \
86
Control_Data::reset(); \
87
rLink = lLink = NullPtr; \
88
} \
89
static Name * key_to_node(Key & __key) \
90
{ \
91
Name * node_zero = 0; \
92
size_t offset = (size_t) &(node_zero->key); \
93
unsigned long addr = (unsigned long)(&__key); \
94
return (Name*) (addr - offset); \
95
}
96
126
# define DECLARE_BINNODE(Name, height, Control_Data) \
127
INIT_CLASS_BINNODE(Name, height, Control_Data) \
128
}; \
129
template <typename Key> Name<Key> * const Name<Key>::NullPtr = NULL; \
130
INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
131
virtual ~Name##Vtl() {
/* empty */
} \
132
}; \
133
template <typename Key> Name##Vtl<Key> * \
134
const Name##Vtl<Key>::NullPtr = NULL
135
170
# define DECLARE_BINNODE_SENTINEL(Name, height, Control_Data) \
171
INIT_CLASS_BINNODE(Name, height, Control_Data) \
172
Name(SentinelCtor) : \
173
Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {}\
174
static Name sentinel_node; \
175
}; \
176
template <typename Key> \
177
Name<Key> Name<Key>::sentinel_node(sentinelCtor); \
178
template <typename Key> \
179
Name<Key> * const Name<Key>::NullPtr = &Name<Key>::sentinel_node;\
180
INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
181
virtual ~Name##Vtl() {
/* empty */
} \
182
private: \
183
Name##Vtl(SentinelCtor) : \
184
Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {}\
185
static Name##Vtl sentinel_node; \
186
}; \
187
template <typename Key> \
188
Name##Vtl<Key> Name##Vtl<Key>::sentinel_node(sentinelCtor); \
189
template <typename Key> \
190
Name##Vtl<Key> * const Name##Vtl<Key>::NullPtr = \
191
&Name##Vtl<Key>::sentinel_node
192
196
# define LLINK(p) ((p)->getL())
197
201
# define RLINK(p) ((p)->getR())
202
206
# define KEY(p) ((p)->get_key())
207
208
DECLARE_BINNODE
(
BinNode
, 2048, Empty_Node);
209
210
211
}
// end namespace Aleph
212
# endif
BinNode
Nodo binario básico.
DECLARE_BINNODE
#define DECLARE_BINNODE(Name, height, Control_Data)
Definition:
tpl_binNode.H:126
Aleph::Empty_Node
Definition:
tpl_binNode.H:11
Leandro Rabindranath León