63 #ifdef PB_DS_DATA_TRUE_INDICATOR
64 #define PB_DS_OV_TREE_NAME ov_tree_map
65 #define PB_DS_CONST_NODE_ITERATOR_NAME ov_tree_node_const_iterator_map
68 #ifdef PB_DS_DATA_FALSE_INDICATOR
69 #define PB_DS_OV_TREE_NAME ov_tree_set
70 #define PB_DS_CONST_NODE_ITERATOR_NAME ov_tree_node_const_iterator_set
73 #define PB_DS_CLASS_T_DEC \
74 template<typename Key, typename Mapped, typename Cmp_Fn, \
75 typename Node_And_It_Traits, typename _Alloc>
77 #define PB_DS_CLASS_C_DEC \
78 PB_DS_OV_TREE_NAME<Key, Mapped, Cmp_Fn, Node_And_It_Traits, _Alloc>
80 #define PB_DS_OV_TREE_TRAITS_BASE \
81 types_traits<Key, Mapped, _Alloc, false>
84 #define PB_DS_DEBUG_MAP_BASE_C_DEC \
85 debug_map_base<Key, eq_by_less<Key, Cmp_Fn>, \
86 typename _Alloc::template rebind<Key>::other::const_reference>
89 #ifdef PB_DS_TREE_TRACE
90 #define PB_DS_TREE_TRACE_BASE_C_DEC \
91 tree_trace_base<typename Node_And_It_Traits::node_const_iterator, \
92 typename Node_And_It_Traits::node_iterator, \
93 Cmp_Fn, false, _Alloc>
96 #ifndef PB_DS_CHECK_KEY_EXISTS
97 # error Missing definition
104 template<
typename Key,
typename Mapped,
typename Cmp_Fn,
105 typename Node_And_It_Traits,
typename _Alloc>
106 class PB_DS_OV_TREE_NAME :
107 #ifdef _GLIBCXX_DEBUG
108 protected PB_DS_DEBUG_MAP_BASE_C_DEC,
110 #ifdef PB_DS_TREE_TRACE
111 public PB_DS_TREE_TRACE_BASE_C_DEC,
114 public Node_And_It_Traits::node_update,
115 public PB_DS_OV_TREE_TRAITS_BASE
119 typedef Node_And_It_Traits traits_type;
121 typedef typename remove_const<typename traits_base::value_type>::type non_const_value_type;
123 typedef typename _Alloc::template rebind<non_const_value_type>::other value_allocator;
124 typedef typename value_allocator::pointer value_vector;
126 #ifdef _GLIBCXX_DEBUG
127 typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base;
130 #ifdef PB_DS_TREE_TRACE
131 typedef PB_DS_TREE_TRACE_BASE_C_DEC trace_base;
134 typedef typename traits_base::pointer mapped_pointer_;
135 typedef typename traits_base::const_pointer mapped_const_pointer_;
137 typedef typename traits_type::metadata_type metadata_type;
139 typedef typename _Alloc::template rebind<metadata_type>::other metadata_allocator;
140 typedef typename metadata_allocator::pointer metadata_pointer;
141 typedef typename metadata_allocator::const_reference metadata_const_reference;
142 typedef typename metadata_allocator::reference metadata_reference;
144 typedef typename traits_type::null_node_update_pointer
145 null_node_update_pointer;
149 typedef _Alloc allocator_type;
150 typedef typename _Alloc::size_type size_type;
151 typedef typename _Alloc::difference_type difference_type;
152 typedef Cmp_Fn cmp_fn;
154 typedef typename traits_base::key_type key_type;
155 typedef typename traits_base::key_pointer key_pointer;
156 typedef typename traits_base::key_const_pointer key_const_pointer;
157 typedef typename traits_base::key_reference key_reference;
158 typedef typename traits_base::key_const_reference key_const_reference;
159 typedef typename traits_base::mapped_type mapped_type;
160 typedef typename traits_base::mapped_pointer mapped_pointer;
161 typedef typename traits_base::mapped_const_pointer mapped_const_pointer;
162 typedef typename traits_base::mapped_reference mapped_reference;
163 typedef typename traits_base::mapped_const_reference mapped_const_reference;
164 typedef typename traits_base::value_type value_type;
165 typedef typename traits_base::pointer pointer;
166 typedef typename traits_base::const_pointer const_pointer;
167 typedef typename traits_base::reference reference;
168 typedef typename traits_base::const_reference const_reference;
170 typedef const_pointer point_const_iterator;
171 #ifdef PB_DS_DATA_TRUE_INDICATOR
172 typedef pointer point_iterator;
174 typedef point_const_iterator point_iterator;
177 typedef point_iterator iterator;
178 typedef point_const_iterator const_iterator;
181 template<
typename Size_Type>
185 cond_dtor(value_vector a_vec, iterator& r_last_it,
186 Size_Type total_size)
187 : m_a_vec(a_vec), m_r_last_it(r_last_it), m_max_size(total_size),
195 iterator it = m_a_vec;
196 while (it != m_r_last_it)
203 value_allocator().deallocate(m_a_vec, m_max_size);
208 { m_no_action =
true; }
211 value_vector m_a_vec;
212 iterator& m_r_last_it;
213 const Size_Type m_max_size;
217 typedef typename traits_type::node_update node_update;
218 typedef typename traits_type::node_iterator node_iterator;
219 typedef typename traits_type::node_const_iterator node_const_iterator;
222 PB_DS_OV_TREE_NAME();
224 PB_DS_OV_TREE_NAME(
const Cmp_Fn&);
226 PB_DS_OV_TREE_NAME(
const Cmp_Fn&,
const node_update&);
228 PB_DS_OV_TREE_NAME(
const PB_DS_CLASS_C_DEC&);
230 ~PB_DS_OV_TREE_NAME();
233 swap(PB_DS_CLASS_C_DEC&);
235 template<
typename It>
237 copy_from_range(It, It);
254 inline mapped_reference
255 operator[](key_const_reference r_key)
257 #ifdef PB_DS_DATA_TRUE_INDICATOR
258 PB_DS_ASSERT_VALID((*
this))
259 point_iterator it = lower_bound(r_key);
260 if (it !=
end() && !Cmp_Fn::operator()(r_key, PB_DS_V2F(*it)))
262 PB_DS_CHECK_KEY_EXISTS(r_key)
263 PB_DS_ASSERT_VALID((*this))
266 return insert_new_val(it,
std::
make_pair(r_key, mapped_type()))->second;
269 return traits_base::s_null_type;
274 insert(const_reference r_value)
276 PB_DS_ASSERT_VALID((*
this))
277 key_const_reference r_key = PB_DS_V2F(r_value);
278 point_iterator it = lower_bound(r_key);
280 if (it !=
end()&& !Cmp_Fn::operator()(r_key, PB_DS_V2F(*it)))
282 PB_DS_ASSERT_VALID((*
this))
283 PB_DS_CHECK_KEY_EXISTS(r_key)
287 return
std::
make_pair(insert_new_val(it, r_value), true);
290 inline point_iterator
291 lower_bound(key_const_reference r_key)
293 pointer it = m_a_values;
294 pointer e_it = m_a_values + m_size;
297 pointer mid_it = it + ((e_it - it) >> 1);
298 if (cmp_fn::operator()(PB_DS_V2F(*mid_it), r_key))
306 inline point_const_iterator
307 lower_bound(key_const_reference r_key)
const
308 {
return const_cast<PB_DS_CLASS_C_DEC&
>(*this).lower_bound(r_key); }
310 inline point_iterator
311 upper_bound(key_const_reference r_key)
313 iterator pot_it = lower_bound(r_key);
314 if (pot_it !=
end() && !Cmp_Fn::operator()(r_key, PB_DS_V2F(*pot_it)))
316 PB_DS_CHECK_KEY_EXISTS(r_key)
320 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
324 inline point_const_iterator
325 upper_bound(key_const_reference r_key)
const
326 {
return const_cast<PB_DS_CLASS_C_DEC&
>(*this).upper_bound(r_key); }
328 inline point_iterator
329 find(key_const_reference r_key)
331 PB_DS_ASSERT_VALID((*
this))
332 iterator pot_it = lower_bound(r_key);
333 if (pot_it !=
end() && !Cmp_Fn::operator()(r_key, PB_DS_V2F(*pot_it)))
335 PB_DS_CHECK_KEY_EXISTS(r_key)
339 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
343 inline point_const_iterator
344 find(key_const_reference r_key)
const
345 {
return (const_cast<PB_DS_CLASS_C_DEC&>(*this).find(r_key)); }
348 erase(key_const_reference);
350 template<
typename Pred>
356 {
return erase_imp<iterator>(it); }
362 join(PB_DS_CLASS_C_DEC&);
365 split(key_const_reference, PB_DS_CLASS_C_DEC&);
369 {
return m_a_values; }
371 inline const_iterator
373 {
return m_a_values; }
379 inline const_iterator
385 inline node_const_iterator
395 inline node_const_iterator
406 update(node_iterator, null_node_update_pointer);
408 template<
typename Node_Update>
410 update(node_iterator, Node_Update*);
413 reallocate_metadata(null_node_update_pointer, size_type);
415 template<
typename Node_Update_>
417 reallocate_metadata(Node_Update_*, size_type);
419 template<
typename It>
421 copy_from_ordered_range(It, It);
424 value_swap(PB_DS_CLASS_C_DEC&);
426 template<
typename It>
428 copy_from_ordered_range(It, It, It, It);
430 template<
typename Ptr>
432 mid_pointer(Ptr p_begin, Ptr p_end)
434 _GLIBCXX_DEBUG_ASSERT(p_end >= p_begin);
435 return (p_begin + (p_end - p_begin) / 2);
439 insert_new_val(iterator it, const_reference r_value)
441 #ifdef PB_DS_REGRESSION
442 typename _Alloc::group_adjustor adjust(m_size);
445 PB_DS_CHECK_KEY_DOES_NOT_EXIST(PB_DS_V2F(r_value))
447 value_vector a_values = s_value_alloc.allocate(m_size + 1);
449 iterator source_it =
begin();
450 iterator source_end_it = end();
451 iterator target_it = a_values;
454 cond_dtor<size_type> cd(a_values, target_it, m_size + 1);
455 while (source_it != it)
457 new (
const_cast<void*
>(
static_cast<const void*
>(target_it)))
458 value_type(*source_it++);
462 new (
const_cast<void*
>(
static_cast<const void*
>(ret_it = target_it)))
466 while (source_it != source_end_it)
468 new (
const_cast<void*
>(
static_cast<const void*
>(target_it)))
469 value_type(*source_it++);
473 reallocate_metadata((node_update*)
this, m_size + 1);
477 cond_dtor<size_type> cd1(m_a_values, m_end_it, m_size);
481 m_a_values = a_values;
482 m_end_it = m_a_values + m_size;
483 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_value)));
484 update(node_begin(), (node_update* )
this);
485 PB_DS_ASSERT_VALID((*
this))
489 #ifdef _GLIBCXX_DEBUG
491 assert_valid(
const char*,
int)
const;
494 assert_iterators(
const char*,
int)
const;
497 template<
typename It>
501 inline node_const_iterator
502 PB_DS_node_begin_imp()
const;
504 inline node_const_iterator
505 PB_DS_node_end_imp()
const;
508 PB_DS_node_begin_imp();
511 PB_DS_node_end_imp();
514 static value_allocator s_value_alloc;
515 static metadata_allocator s_metadata_alloc;
517 value_vector m_a_values;
518 metadata_pointer m_a_metadata;
532 #undef PB_DS_CLASS_C_DEC
533 #undef PB_DS_CLASS_T_DEC
534 #undef PB_DS_OV_TREE_NAME
535 #undef PB_DS_OV_TREE_TRAITS_BASE
536 #undef PB_DS_DEBUG_MAP_BASE_C_DEC
537 #ifdef PB_DS_TREE_TRACE
538 #undef PB_DS_TREE_TRACE_BASE_C_DEC
540 #undef PB_DS_CONST_NODE_ITERATOR_NAME
auto end(_Container &__cont) -> decltype(__cont.end())
Return an iterator pointing to one past the last element of the container.
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.
ISO C++ entities toplevel namespace is std.
auto begin(_Container &__cont) -> decltype(__cont.begin())
Return an iterator pointing to the first element of the container.
GNU extensions for policy-based data structures for public use.
void swap(_Tp &, _Tp &) noexcept(__and_< is_nothrow_move_constructible< _Tp >, is_nothrow_move_assignable< _Tp >>::value)
Swaps two values.
Struct holding two objects of arbitrary type.