41 #ifndef PB_DS_BINARY_HEAP_HPP
42 #define PB_DS_BINARY_HEAP_HPP
54 #ifdef PB_DS_BINARY_HEAP_TRACE_
64 #define PB_DS_CLASS_T_DEC \
65 template<typename Value_Type, typename Cmp_Fn, typename _Alloc>
67 #define PB_DS_CLASS_C_DEC \
68 binary_heap<Value_Type, Cmp_Fn, _Alloc>
70 #define PB_DS_ENTRY_CMP_DEC \
71 entry_cmp<Value_Type, Cmp_Fn, _Alloc, is_simple<Value_Type>::value>::type
73 #define PB_DS_RESIZE_POLICY_DEC \
74 __gnu_pbds::detail::resize_policy<typename _Alloc::size_type>
83 template<
typename Value_Type,
typename Cmp_Fn,
typename _Alloc>
85 :
public PB_DS_ENTRY_CMP_DEC,
public PB_DS_RESIZE_POLICY_DEC
88 typedef Value_Type value_type;
89 typedef Cmp_Fn cmp_fn;
90 typedef _Alloc allocator_type;
91 typedef typename _Alloc::size_type size_type;
92 typedef typename _Alloc::difference_type difference_type;
93 typedef typename PB_DS_ENTRY_CMP_DEC entry_cmp;
100 simple_value = is_simple<value_type>::value
103 typedef integral_constant<int, simple_value> no_throw_copies_t;
105 typedef typename _Alloc::template rebind<value_type> __rebind_v;
106 typedef typename __rebind_v::other value_allocator;
109 typedef typename value_allocator::pointer pointer;
110 typedef typename value_allocator::const_pointer const_pointer;
111 typedef typename value_allocator::reference reference;
112 typedef typename value_allocator::const_reference const_reference;
114 typedef typename __conditional_type<simple_value,
115 value_type, pointer>::__type
118 typedef typename _Alloc::template rebind<entry>::other
121 typedef typename entry_allocator::pointer entry_pointer;
124 simple_value, _Alloc>
130 simple_value, _Alloc>
163 push(const_reference);
168 inline const_reference
177 template<
typename Pred>
182 erase_at(entry_pointer, size_type, false_type);
185 erase_at(entry_pointer, size_type, true_type);
202 template<
typename Pred>
209 #ifdef PB_DS_BINARY_HEAP_TRACE_
215 template<
typename It>
217 copy_from_range(It, It);
224 insert_value(const_reference, false_type);
227 insert_value(value_type, true_type);
230 resize_for_insert_if_needed();
233 swap_value_imp(entry_pointer, value_type, true_type);
236 swap_value_imp(entry_pointer, const_reference, false_type);
241 inline const_reference
242 top_imp(true_type)
const;
244 inline const_reference
245 top_imp(false_type)
const;
247 inline static size_type
248 left_child(size_type);
250 inline static size_type
251 right_child(size_type);
253 inline static size_type
257 resize_for_erase_if_needed();
259 template<
typename Pred>
266 const entry_cmp& m_cmp =
static_cast<entry_cmp&
>(*this);
267 entry_pointer end = m_a_entries + m_size;
268 std::make_heap(m_a_entries, end, m_cmp);
269 _GLIBCXX_DEBUG_ASSERT(is_heap());
279 const entry_cmp& m_cmp =
static_cast<entry_cmp&
>(*this);
280 entry_pointer end = m_a_entries + m_size;
281 std::push_heap(m_a_entries, end, m_cmp);
288 const entry_cmp& m_cmp =
static_cast<entry_cmp&
>(*this);
289 entry_pointer end = m_a_entries + m_size;
290 std::pop_heap(m_a_entries, end, m_cmp);
296 const entry_cmp& m_cmp =
static_cast<entry_cmp&
>(*this);
297 entry_pointer end = m_a_entries + m_size;
298 bool p = std::__is_heap(m_a_entries, end, m_cmp);
302 #ifdef _GLIBCXX_DEBUG
304 assert_valid(
const char*,
int)
const;
307 #ifdef PB_DS_BINARY_HEAP_TRACE_
309 trace_entry(
const entry&, false_type)
const;
312 trace_entry(
const entry&, true_type)
const;
315 static entry_allocator s_entry_allocator;
316 static value_allocator s_value_allocator;
317 static no_throw_copies_t s_no_throw_copies_ind;
320 size_type m_actual_size;
321 entry_pointer m_a_entries;
324 #define PB_DS_ASSERT_VALID(X) \
325 _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);)
327 #define PB_DS_DEBUG_VERIFY(_Cond) \
328 _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \
329 _M_message(#_Cond" assertion from %1;:%2;") \
330 ._M_string(__FILE__)._M_integer(__LINE__) \
344 #undef PB_DS_CLASS_C_DEC
345 #undef PB_DS_CLASS_T_DEC
346 #undef PB_DS_ENTRY_CMP_DEC
347 #undef PB_DS_RESIZE_POLICY_DEC
Conditional deallocate constructor argument.
Resize policy for binary heap.
Const point-type iterator.
Const point-type iterator.