49# include <type_traits>
133 namespace bin_node_detail
144 template <
typename Key>
146 std::is_nothrow_default_constructible_v<Key>;
149 template <
typename First,
typename Second>
150 inline constexpr bool nothrow_default_key_v<std::pair<First, Second>> =
151 nothrow_default_key_v<First>
and nothrow_default_key_v<Second>;
156 template <
class Node>
157 using key_of_t = std::remove_cvref_t<decltype(std::declval<Node &>().get_key())>;
168 template <
class Node>
170 noexcept(std::declval<Node &>().get_key())
and
180 template <
class Node>
182 std::is_nothrow_default_constructible_v<Node> or nothrow_from_key_of_v<Node>;
216 template <
class Node>
218 noexcept(nothrow_header_from_v<Node>)
220 if constexpr (std::is_nothrow_default_constructible_v<Node> or
221 not nothrow_from_key_of_v<Node>)
224 return Node(std::move(other.get_key()));
241 template <
class Compare>
244 if constexpr (std::is_copy_constructible_v<Compare>)
245 return static_cast<const Compare &
>(
cmp);
246 else if constexpr (std::is_constructible_v<Compare, Compare &>)
247 return static_cast<Compare &
>(
cmp);
249 return std::move(
cmp);
256 template <
class Compare>
258 std::is_nothrow_constructible_v<Compare,
277# if defined(__GNUC__) || defined(__clang__)
278 __builtin_unreachable();
279# elif defined(_MSC_VER)
285# define INIT_CLASS_BINNODE(Name, height, Control_Data) \
286 template <typename Key> \
287 class Name : public Control_Data \
290 static const size_t MaxHeight = height; \
291 static Name * const NullPtr; \
292 typedef Key key_type; \
293 typedef Key Key_Type; \
303 Key & get_key() noexcept { return key; } \
304 const Key & get_key() const noexcept { return key; } \
305 Name *& getL() noexcept { return lLink; } \
306 Name *& getR() noexcept { return rLink; } \
307 const Name * getL() const noexcept { return lLink; } \
308 const Name * getR() const noexcept { return rLink; } \
310 : key(k), lLink(NullPtr), rLink(NullPtr) \
312 static_assert(std::is_copy_constructible<Key>::value, \
313 "No copy constructor for Key"); \
319 noexcept(std::is_nothrow_move_constructible_v<Key> and \
320 std::is_nothrow_default_constructible_v<Control_Data>) \
321 : key(std::move(k)), lLink(NullPtr), rLink(NullPtr) \
323 static_assert(std::is_move_constructible<Key>::value, \
324 "No move constructor for Key"); \
326 Name(const Control_Data & control_data, const Key & k) \
327 : Control_Data(control_data), \
328 key(k), lLink(NullPtr), rLink(NullPtr) \
332 Name(const Name & node) \
333 : Control_Data(node), \
334 key(node.key), lLink(NullPtr), rLink(NullPtr) \
339 : Control_Data(std::move(static_cast<Control_Data &>(node))), \
340 key(std::move(node.key)), lLink(NullPtr), rLink(NullPtr) \
347 Name(const Control_Data & control_data) \
348 noexcept(Aleph::bin_node_detail::nothrow_default_key_v<Key> and \
349 std::is_nothrow_copy_constructible_v<Control_Data>) : \
350 Control_Data(control_data), \
351 lLink(NullPtr), rLink(NullPtr) \
358 noexcept(Aleph::bin_node_detail::nothrow_default_key_v<Key> and \
359 std::is_nothrow_default_constructible_v<Control_Data>) \
360 : lLink(NullPtr), rLink(NullPtr) \
362 static_assert(std::is_default_constructible<Key>::value, \
363 "No default constructor for Key"); \
365 void reset() noexcept \
367 Control_Data::reset(); \
368 rLink = lLink = NullPtr; \
370 static Name * key_to_node(Key & __key) noexcept \
372 const size_t offset = __builtin_offsetof(Name, key); \
373 char * addr = reinterpret_cast<char *>(&__key); \
374 return reinterpret_cast<Name *>(addr - offset); \
401# define DECLARE_BINNODE(Name, height, Control_Data) \
402 INIT_CLASS_BINNODE(Name, height, Control_Data) \
404 template <typename Key> Name<Key> * const Name<Key>::NullPtr = nullptr; \
405 INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
406 virtual ~Name##Vtl() { } \
408 template <typename Key> Name##Vtl<Key> * \
409 const Name##Vtl<Key>::NullPtr = nullptr
449# define DECLARE_BINNODE_SENTINEL(Name, height, Control_Data) \
450 INIT_CLASS_BINNODE(Name, height, Control_Data) \
451 Name(SentinelCtor) : \
452 Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {} \
453 static Name sentinel_node; \
455 template <typename Key> \
456 Name<Key> Name<Key>::sentinel_node(sentinelCtor); \
457 template <typename Key> \
458 Name<Key> * const Name<Key>::NullPtr = &Name<Key>::sentinel_node; \
459 INIT_CLASS_BINNODE(Name##Vtl, height, Control_Data) \
460 virtual ~Name##Vtl() { } \
461 Name##Vtl(SentinelCtor) : \
462 Control_Data(sentinelCtor), lLink(NullPtr), rLink(NullPtr) {} \
463 static Name##Vtl sentinel_node; \
465 template <typename Key> \
466 Name##Vtl<Key> Name##Vtl<Key>::sentinel_node(sentinelCtor); \
467 template <typename Key> \
468 Name##Vtl<Key> * const Name##Vtl<Key>::NullPtr = \
469 &Name##Vtl<Key>::sentinel_node
474 template <
class Node>
480 template <
class Node>
490 template <
class Node>
496 template <
class Node>
506 template <
class Node>
508 typename Node::Key_Type &
KEY(
Node *p)
noexcept
513 template <
class Node>
515 const typename Node::Key_Type &
KEY(
const Node *p)
noexcept
520 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
Basic binary node with no extra control data.
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
#define DECLARE_BINNODE(Name, height, Control_Data)
Specify tree node for a binary tree.
constexpr decltype(auto) compare_to_take(Compare &cmp) noexcept
What a tree that takes the nodes of another takes of its comparison criteria.
constexpr bool nothrow_header_from_v
Whether header_from() builds a header node without throwing.
constexpr bool nothrow_from_key_of_v
Whether a node is built without throwing from the key of another node, which is moved.
constexpr bool nothrow_default_key_v
Whether building a Key by default throws nothing.
std::remove_cvref_t< decltype(std::declval< Node & >().get_key())> key_of_t
The type of the key of a node, as its get_key() gives it.
constexpr bool nothrow_compare_taken_v
Whether a tree takes without throwing the comparison criteria that compare_to_take() gives it.
Node header_from(Node &other) noexcept(nothrow_header_from_v< Node >)
Builds a header node of a tree that takes the nodes of another tree.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
static void reset() noexcept
Empty_Node(SentinelCtor) noexcept
static Empty_Node & get_data()
static constexpr node_type *& left(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
typename Node::Key_Type key_type