66 #ifdef PB_DS_DATA_TRUE_INDICATOR
67 #define PB_DS_PAT_TRIE_NAME pat_trie_map
70 #ifdef PB_DS_DATA_FALSE_INDICATOR
71 #define PB_DS_PAT_TRIE_NAME pat_trie_set
74 #define PB_DS_CLASS_T_DEC \
75 template<typename Key, typename Mapped, typename Node_And_It_Traits, \
78 #define PB_DS_CLASS_C_DEC \
79 PB_DS_PAT_TRIE_NAME<Key, Mapped, Node_And_It_Traits, _Alloc>
81 #define PB_DS_PAT_TRIE_TRAITS_BASE \
82 types_traits<Key, Mapped, _Alloc, false>
85 #define PB_DS_DEBUG_MAP_BASE_C_DEC \
86 debug_map_base<Key, eq_by_less<Key, std::less<Key> >, \
87 typename _Alloc::template rebind<Key>::other::const_reference>
100 template<
typename Key,
typename Mapped,
typename Node_And_It_Traits,
102 class PB_DS_PAT_TRIE_NAME :
103 #ifdef _GLIBCXX_DEBUG
104 public PB_DS_DEBUG_MAP_BASE_C_DEC,
106 public Node_And_It_Traits::synth_access_traits,
107 public Node_And_It_Traits::node_update,
108 public PB_DS_PAT_TRIE_TRAITS_BASE,
114 typedef Node_And_It_Traits traits_type;
116 typedef typename traits_type::synth_access_traits synth_access_traits;
117 typedef typename synth_access_traits::const_iterator a_const_iterator;
119 typedef typename traits_type::node node;
120 typedef typename _Alloc::template rebind<node> __rebind_n;
121 typedef typename __rebind_n::other::const_pointer node_const_pointer;
122 typedef typename __rebind_n::other::pointer node_pointer;
124 typedef typename traits_type::head head;
125 typedef typename _Alloc::template rebind<head> __rebind_h;
126 typedef typename __rebind_h::other head_allocator;
127 typedef typename head_allocator::pointer head_pointer;
129 typedef typename traits_type::leaf leaf;
130 typedef typename _Alloc::template rebind<leaf> __rebind_l;
131 typedef typename __rebind_l::other leaf_allocator;
132 typedef typename leaf_allocator::pointer leaf_pointer;
133 typedef typename leaf_allocator::const_pointer leaf_const_pointer;
135 typedef typename traits_type::inode inode;
136 typedef typename inode::iterator inode_iterator;
137 typedef typename _Alloc::template rebind<inode> __rebind_in;
138 typedef typename __rebind_in::other __rebind_ina;
139 typedef typename __rebind_in::other inode_allocator;
140 typedef typename __rebind_ina::pointer inode_pointer;
141 typedef typename __rebind_ina::const_pointer inode_const_pointer;
149 bool m_no_action_dtor;
150 bool m_call_destructor;
153 cond_dealtor(leaf_pointer p_nd)
154 : m_p_nd(p_nd), m_no_action_dtor(
false), m_call_destructor(
false)
159 { m_no_action_dtor =
true; }
162 set_call_destructor()
163 { m_call_destructor =
true; }
167 if (m_no_action_dtor)
170 if (m_call_destructor)
173 s_leaf_allocator.deallocate(m_p_nd, 1);
182 typedef inode_pointer __inp;
183 typedef typename _Alloc::template rebind<__inp>::other __rebind_inp;
185 #ifdef _GLIBCXX_DEBUG
186 typedef std::_GLIBCXX_STD_C::list<__inp, __rebind_inp> bag_type;
196 inode_pointer p_nd = s_inode_allocator.allocate(1);
199 m_bag.push_back(p_nd);
203 s_inode_allocator.deallocate(p_nd, 1);
204 __throw_exception_again;
211 _GLIBCXX_DEBUG_ASSERT(!m_bag.empty());
212 inode_pointer p_nd = *m_bag.begin();
219 while (!m_bag.empty())
221 inode_pointer p_nd = *m_bag.begin();
222 s_inode_allocator.deallocate(p_nd, 1);
229 {
return m_bag.empty(); }
232 #ifdef _GLIBCXX_DEBUG
233 typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base;
236 typedef typename traits_type::null_node_update_pointer null_node_update_pointer;
239 typedef pat_trie_tag container_category;
240 typedef _Alloc allocator_type;
241 typedef typename _Alloc::size_type size_type;
242 typedef typename _Alloc::difference_type difference_type;
244 typedef typename traits_base::key_type key_type;
245 typedef typename traits_base::key_pointer key_pointer;
246 typedef typename traits_base::key_const_pointer key_const_pointer;
247 typedef typename traits_base::key_reference key_reference;
248 typedef typename traits_base::key_const_reference key_const_reference;
249 typedef typename traits_base::mapped_type mapped_type;
250 typedef typename traits_base::mapped_pointer mapped_pointer;
251 typedef typename traits_base::mapped_const_pointer mapped_const_pointer;
252 typedef typename traits_base::mapped_reference mapped_reference;
253 typedef typename traits_base::mapped_const_reference mapped_const_reference;
254 typedef typename traits_base::value_type value_type;
255 typedef typename traits_base::pointer pointer;
256 typedef typename traits_base::const_pointer const_pointer;
257 typedef typename traits_base::reference reference;
258 typedef typename traits_base::const_reference const_reference;
260 typedef typename traits_type::access_traits access_traits;
261 typedef typename traits_type::const_iterator point_const_iterator;
262 typedef typename traits_type::iterator point_iterator;
263 typedef point_const_iterator const_iterator;
264 typedef point_iterator iterator;
266 typedef typename traits_type::reverse_iterator reverse_iterator;
267 typedef typename traits_type::const_reverse_iterator const_reverse_iterator;
268 typedef typename traits_type::node_const_iterator node_const_iterator;
269 typedef typename traits_type::node_iterator node_iterator;
270 typedef typename traits_type::node_update node_update;
272 PB_DS_PAT_TRIE_NAME();
274 PB_DS_PAT_TRIE_NAME(
const access_traits&);
276 PB_DS_PAT_TRIE_NAME(
const PB_DS_CLASS_C_DEC&);
279 swap(PB_DS_CLASS_C_DEC&);
281 ~PB_DS_PAT_TRIE_NAME();
296 get_access_traits()
const;
302 get_node_update()
const;
305 insert(const_reference);
307 inline mapped_reference
310 #ifdef PB_DS_DATA_TRUE_INDICATOR
311 return insert(
std::make_pair(r_key, mapped_type())).first->second;
314 return traits_base::s_null_type;
318 inline point_iterator
319 find(key_const_reference);
321 inline point_const_iterator
322 find(key_const_reference)
const;
324 inline point_iterator
325 lower_bound(key_const_reference);
327 inline point_const_iterator
328 lower_bound(key_const_reference)
const;
330 inline point_iterator
331 upper_bound(key_const_reference);
333 inline point_const_iterator
334 upper_bound(key_const_reference)
const;
340 erase(key_const_reference);
342 inline const_iterator
343 erase(const_iterator);
345 #ifdef PB_DS_DATA_TRUE_INDICATOR
350 inline const_reverse_iterator
351 erase(const_reverse_iterator);
353 #ifdef PB_DS_DATA_TRUE_INDICATOR
354 inline reverse_iterator
355 erase(reverse_iterator);
358 template<
typename Pred>
363 join(PB_DS_CLASS_C_DEC&);
366 split(key_const_reference, PB_DS_CLASS_C_DEC&);
371 inline const_iterator
377 inline const_iterator
380 inline reverse_iterator
383 inline const_reverse_iterator
386 inline reverse_iterator
389 inline const_reverse_iterator
394 inline node_const_iterator
404 inline node_const_iterator
412 #ifdef PB_DS_PAT_TRIE_TRACE_
418 template<
typename It>
420 copy_from_range(It, It);
423 value_swap(PB_DS_CLASS_C_DEC&);
426 recursive_copy_node(node_const_pointer);
433 apply_update(node_pointer, null_node_update_pointer);
435 template<
typename Node_Update_>
437 apply_update(node_pointer, Node_Update_*);
440 join_prep(PB_DS_CLASS_C_DEC&, branch_bag&);
443 rec_join_prep(node_const_pointer, node_const_pointer, branch_bag&);
446 rec_join_prep(leaf_const_pointer, leaf_const_pointer, branch_bag&);
449 rec_join_prep(leaf_const_pointer, inode_const_pointer, branch_bag&);
452 rec_join_prep(inode_const_pointer, leaf_const_pointer, branch_bag&);
455 rec_join_prep(inode_const_pointer, inode_const_pointer, branch_bag&);
458 rec_join(node_pointer, node_pointer, size_type, branch_bag&);
461 rec_join(leaf_pointer, leaf_pointer, branch_bag&);
464 rec_join(leaf_pointer, inode_pointer, size_type, branch_bag&);
467 rec_join(inode_pointer, leaf_pointer, size_type, branch_bag&);
470 rec_join(inode_pointer, inode_pointer, branch_bag&);
473 keys_diff_ind(
typename access_traits::const_iterator,
474 typename access_traits::const_iterator,
475 typename access_traits::const_iterator,
476 typename access_traits::const_iterator);
479 insert_branch(node_pointer, node_pointer, branch_bag&);
482 update_min_max_for_inserted_leaf(leaf_pointer);
485 erase_leaf(leaf_pointer);
488 actual_erase_leaf(leaf_pointer);
491 clear_imp(node_pointer);
494 erase_fixup(inode_pointer);
497 update_min_max_for_erased_leaf(leaf_pointer);
499 static inline a_const_iterator
500 pref_begin(node_const_pointer);
502 static inline a_const_iterator
503 pref_end(node_const_pointer);
506 find_imp(key_const_reference);
509 lower_bound_imp(key_const_reference);
512 upper_bound_imp(key_const_reference);
514 inline static leaf_const_pointer
515 leftmost_descendant(node_const_pointer);
517 inline static leaf_pointer
518 leftmost_descendant(node_pointer);
520 inline static leaf_const_pointer
521 rightmost_descendant(node_const_pointer);
523 inline static leaf_pointer
524 rightmost_descendant(node_pointer);
526 #ifdef _GLIBCXX_DEBUG
528 assert_valid(
const char*,
int)
const;
531 assert_iterators(
const char*,
int)
const;
534 assert_reverse_iterators(
const char*,
int)
const;
537 recursive_count_leafs(node_const_pointer,
const char*,
int);
540 #ifdef PB_DS_PAT_TRIE_TRACE_
542 trace_node(node_const_pointer, size_type);
544 template<
typename Metadata_>
546 trace_node_metadata(node_const_pointer, type_to_type<Metadata_>);
549 trace_node_metadata(node_const_pointer, type_to_type<null_type>);
553 split_prep(key_const_reference, PB_DS_CLASS_C_DEC&, branch_bag&);
556 rec_split(node_pointer, a_const_iterator, a_const_iterator,
557 PB_DS_CLASS_C_DEC&, branch_bag&);
560 split_insert_branch(size_type, a_const_iterator, inode_iterator,
561 size_type, branch_bag&);
563 static head_allocator s_head_allocator;
564 static inode_allocator s_inode_allocator;
565 static leaf_allocator s_leaf_allocator;
567 head_pointer m_p_head;
571 #define PB_DS_ASSERT_NODE_VALID(X) \
572 _GLIBCXX_DEBUG_ONLY(X->assert_valid(this, __FILE__, __LINE__);)
574 #define PB_DS_RECURSIVE_COUNT_LEAFS(X) \
575 recursive_count_leafs(X, __FILE__, __LINE__)
589 #undef PB_DS_RECURSIVE_COUNT_LEAFS
590 #undef PB_DS_ASSERT_NODE_VALID
591 #undef PB_DS_CLASS_C_DEC
592 #undef PB_DS_CLASS_T_DEC
593 #undef PB_DS_PAT_TRIE_NAME
594 #undef PB_DS_PAT_TRIE_TRAITS_BASE
595 #undef PB_DS_DEBUG_MAP_BASE_C_DEC
Base type for PATRICIA trees.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initilizer_list.
reference operator[](size_t __position)
Array-indexing support.
Struct holding two objects of arbitrary type.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initilizer_list.
constexpr size_t size() const _GLIBCXX_NOEXCEPT
Returns the total number of bits.