00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 # ifndef TPL_BINNODE_H
00045 # define TPL_BINNODE_H
00046
00047 # include <ahDefs.H>
00048 # include <ahAssert.H>
00049
00050 namespace Aleph {
00051
00052 struct Empty_Node
00053 {
00054 Empty_Node() { }
00055
00056 Empty_Node(SentinelCtor) { }
00057
00058 void reset() { }
00059
00060 Empty_Node & get_data()
00061 {
00062 throw std::domain_error("Empty_Node has not data");
00063 }
00064 };
00065
00066 # define INIT_CLASS_BINNODE(Name, height, Control_Data) \
00067 template <typename Key> \
00068 class Name : public Control_Data \
00069 { \
00070 public: \
00071 \
00072 static const size_t MaxHeight = height; \
00073 static Name * const NullPtr; \
00074 \
00075 typedef Key key_type; \
00076 \
00077 private: \
00078 \
00079 Key key; \
00080 Name * lLink; \
00081 Name * rLink; \
00082 \
00083 public: \
00084 \
00085 Key & get_key() { return key; } \
00086 \
00087 const Key & get_key() const { return key; } \
00088 \
00089 Name *& getL() { return lLink; } \
00090 \
00091 Name *& getR() { return rLink; } \
00092 \
00093 Name(const Key& k) : key(k), lLink(NullPtr), rLink(NullPtr) \
00094 { \
00095 \
00096 } \
00097 \
00098 Name(const Control_Data & control_data, const Key & k) : \
00099 Control_Data(control_data), \
00100 key(k), lLink(NullPtr), rLink(NullPtr) \
00101 { \
00102 \
00103 } \
00104 \
00105 Name(const Name & node) : \
00106 Control_Data(node), \
00107 key(node.key), lLink(NullPtr), rLink(NullPtr) \
00108 { \
00109 \
00110 } \
00111 \
00112 Name(const Control_Data & control_data) : \
00113 Control_Data(control_data), \
00114 lLink(NullPtr), rLink(NullPtr) \
00115 { \
00116 \
00117 } \
00118 \
00119 Name() : lLink(NullPtr), rLink(NullPtr) \
00120 { \
00121 \
00122 } \
00123 \
00124 void reset() \
00125 { \
00126 Control_Data::reset(); \
00127 rLink = lLink = NullPtr; \
00128 } \
00129 \
00130 static Name * key_to_node(Key & __key) \
00131 { \
00132 Name * node_zero = 0; \
00133 size_t offset = (size_t) &(node_zero->key); \
00134 char * addr = &__key; \
00135 \
00136 return (Name*) (addr - offset); \
00137 }
00138
00168 # define DECLARE_BINNODE(Name, height, Control_Data) \
00169 INIT_CLASS_BINNODE(Name, height, Control_Data) \
00170 }; \
00171 \
00172 template <typename Key> Name<Key> * const Name<Key>::NullPtr = NULL; \
00173 \
00174 INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
00175 virtual ~Name##Vtl() { } \
00176 }; \
00177 \
00178 template <typename Key> Name##Vtl<Key> * const Name##Vtl<Key>::NullPtr = NULL
00179
00213 # define DECLARE_BINNODE_SENTINEL(Name, height, Control_Data) \
00214 INIT_CLASS_BINNODE(Name, height, Control_Data) \
00215 Name(SentinelCtor) : \
00216 Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {}\
00217 static Name sentinel_node; \
00218 }; \
00219 \
00220 template <typename Key> \
00221 Name<Key> Name<Key>::sentinel_node(sentinelCtor); \
00222 \
00223 template <typename Key> \
00224 Name<Key> * const Name<Key>::NullPtr = &Name<Key>::sentinel_node;\
00225 \
00226 INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
00227 virtual ~Name##Vtl() { } \
00228 private: \
00229 Name##Vtl(SentinelCtor) : \
00230 Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {}\
00231 static Name##Vtl sentinel_node; \
00232 }; \
00233 \
00234 template <typename Key> \
00235 Name##Vtl<Key> Name##Vtl<Key>::sentinel_node(sentinelCtor); \
00236 \
00237 template <typename Key> \
00238 Name##Vtl<Key> * const Name##Vtl<Key>::NullPtr = \
00239 &Name##Vtl<Key>::sentinel_node
00240
00243 # define LLINK(p) ((p)->getL())
00244
00247 # define RLINK(p) ((p)->getR())
00248
00251 # define KEY(p) ((p)->get_key())
00252
00253 DECLARE_BINNODE(BinNode, 1024, Empty_Node);
00283 }
00284
00285 # endif
00286