49# include <type_traits>
152# define INIT_CLASS_BINNODE(Name, height, Control_Data) \
153 template <typename Key> \
154 class Name : public Control_Data \
157 static const size_t MaxHeight = height; \
158 static Name * const NullPtr; \
159 typedef Key key_type; \
160 typedef Key Key_Type; \
170 Key & get_key() noexcept { return key; } \
171 const Key & get_key() const noexcept { return key; } \
172 Name *& getL() noexcept { return lLink; } \
173 Name *& getR() noexcept { return rLink; } \
174 const Name * getL() const noexcept { return lLink; } \
175 const Name * getR() const noexcept { return rLink; } \
177 : key(k), lLink(NullPtr), rLink(NullPtr) \
179 static_assert(std::is_copy_constructible<Key>::value, \
180 "No copy constructor for Key"); \
182 Name(Key && k) noexcept \
183 : key(std::move(k)), lLink(NullPtr), rLink(NullPtr) \
185 static_assert(std::is_move_constructible<Key>::value, \
186 "No move constructor for Key"); \
188 Name(const Control_Data & control_data, const Key & k) \
189 : Control_Data(control_data), \
190 key(k), lLink(NullPtr), rLink(NullPtr) \
194 Name(const Name & node) \
195 : Control_Data(node), \
196 key(node.key), lLink(NullPtr), rLink(NullPtr) \
201 : Control_Data(std::move(static_cast<Control_Data &>(node))), \
202 key(std::move(node.key)), lLink(NullPtr), rLink(NullPtr) \
206 Name(const Control_Data & control_data) noexcept : \
207 Control_Data(control_data), \
208 lLink(NullPtr), rLink(NullPtr) \
213 : lLink(NullPtr), rLink(NullPtr) \
215 static_assert(std::is_default_constructible<Key>::value, \
216 "No default constructor for Key"); \
218 void reset() noexcept \
220 Control_Data::reset(); \
221 rLink = lLink = NullPtr; \
223 static Name * key_to_node(Key & __key) noexcept \
225 Name * node_zero = 0; \
226 size_t offset = (size_t) &(node_zero->key); \
227 unsigned long addr = (unsigned long)(&__key); \
228 return (Name*) (addr - offset); \
255# define DECLARE_BINNODE(Name, height, Control_Data) \
256 INIT_CLASS_BINNODE(Name, height, Control_Data) \
258 template <typename Key> Name<Key> * const Name<Key>::NullPtr = nullptr; \
259 INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
260 virtual ~Name##Vtl() { } \
262 template <typename Key> Name##Vtl<Key> * \
263 const Name##Vtl<Key>::NullPtr = nullptr
295# define DECLARE_BINNODE_SENTINEL(Name, height, Control_Data) \
296 INIT_CLASS_BINNODE(Name, height, Control_Data) \
297 Name(SentinelCtor) : \
298 Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {} \
299 static Name sentinel_node; \
301 template <typename Key> \
302 Name<Key> Name<Key>::sentinel_node(sentinelCtor); \
303 template <typename Key> \
304 Name<Key> * const Name<Key>::NullPtr = &Name<Key>::sentinel_node; \
305 INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
306 virtual ~Name##Vtl() { } \
308 Name##Vtl(SentinelCtor) : \
309 Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {} \
310 static Name##Vtl sentinel_node; \
312 template <typename Key> \
313 Name##Vtl<Key> Name##Vtl<Key>::sentinel_node(sentinelCtor); \
314 template <typename Key> \
315 Name##Vtl<Key> * const Name##Vtl<Key>::NullPtr = \
316 &Name##Vtl<Key>::sentinel_node
321 template <
class Node>
327 template <
class Node>
337 template <
class Node>
343 template <
class Node>
353 template <
class Node>
355 typename Node::Key_Type &
KEY(
Node *p)
noexcept
360 template <
class Node>
362 const typename Node::Key_Type &
KEY(
const Node *p)
noexcept
367 template <
class Node>
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error()
Throws std::domain_error unconditionally.
Debug assertion and warning utilities.
Core definitions, constants, and utility macros for Aleph-w.
SentinelCtor
Tag type for sentinel node construction.
WeightedDigraph::Node Node
Node for binary search tree.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
#define DECLARE_BINNODE(Name, height, Control_Data)
Specify tree node for a binary tree.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
static void reset() noexcept
Empty_Node(SentinelCtor) noexcept
static Empty_Node & get_data()
static constexpr node_type *& left(node_type *p) noexcept
static const node_type * left(const node_type *p) noexcept
static constexpr node_type *& right(node_type *p) noexcept
static key_type & key(node_type *p) noexcept
static constexpr node_type * null() noexcept
static const key_type & key(const node_type *p) noexcept
typename Node::Key_Type key_type
static const node_type * right(const node_type *p) noexcept