3 // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
37 * @file left_child_next_sibling_heap_.hpp
38 * Contains an implementation class for a basic heap.
41 #ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP
42 #define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP
49 #include <ext/pb_ds/detail/cond_dealtor.hpp>
50 #include <ext/pb_ds/detail/type_utils.hpp>
51 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp>
52 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/const_point_iterator.hpp>
53 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp>
54 #ifdef PB_DS_LC_NS_HEAP_TRACE_
57 #include <debug/debug.h>
65 #define PB_DS_CLASS_T_DEC \
67 typename Value_Type, \
69 typename Node_Metadata, \
71 bool Single_Link_Roots>
73 #define PB_DS_CLASS_T_DEC \
75 typename Value_Type, \
77 typename Node_Metadata, \
82 #define PB_DS_CLASS_C_DEC \
83 left_child_next_sibling_heap_< \
90 #define PB_DS_CLASS_C_DEC \
91 left_child_next_sibling_heap_< \
99 * class description = "Base class for some types of h3ap$">
101 #ifdef _GLIBCXX_DEBUG
102 template<typename Value_Type,
104 typename Node_Metadata,
106 bool Single_Link_Roots>
108 template<typename Value_Type,
110 typename Node_Metadata,
113 class left_child_next_sibling_heap_ : public Cmp_Fn
118 typename Allocator::template rebind<
119 left_child_next_sibling_heap_node_<
125 typedef typename node_allocator::value_type node;
127 typedef typename node_allocator::pointer node_pointer;
129 typedef typename node_allocator::const_pointer const_node_pointer;
131 typedef Node_Metadata node_metadata;
133 typedef std::pair< node_pointer, node_pointer> node_pointer_pair;
136 typedef cond_dealtor< node, Allocator> cond_dealtor_t;
140 simple_value = is_simple<Value_Type>::value
143 typedef integral_constant<int, simple_value> no_throw_copies_t;
147 typedef typename Allocator::size_type size_type;
149 typedef typename Allocator::difference_type difference_type;
151 typedef Value_Type value_type;
154 typename Allocator::template rebind<
155 value_type>::other::pointer
159 typename Allocator::template rebind<
160 value_type>::other::const_pointer
164 typename Allocator::template rebind<
165 value_type>::other::reference
169 typename Allocator::template rebind<
170 value_type>::other::const_reference
174 left_child_next_sibling_heap_node_const_point_iterator_<
177 const_point_iterator;
179 typedef const_point_iterator point_iterator;
182 left_child_next_sibling_heap_const_iterator_<
187 typedef const_iterator iterator;
189 typedef Cmp_Fn cmp_fn;
191 typedef Allocator allocator_type;
195 left_child_next_sibling_heap_();
197 left_child_next_sibling_heap_(const Cmp_Fn& r_cmp_fn);
199 left_child_next_sibling_heap_(const PB_DS_CLASS_C_DEC& other);
202 swap(PB_DS_CLASS_C_DEC& other);
204 ~left_child_next_sibling_heap_();
224 inline const_iterator
230 inline const_iterator
236 #ifdef PB_DS_LC_NS_HEAP_TRACE_
244 get_new_node_for_insert(const_reference r_val);
247 make_child_of(node_pointer p_nd, node_pointer p_new_parent);
250 value_swap(PB_DS_CLASS_C_DEC& other);
252 inline static node_pointer
253 parent(node_pointer p_nd);
256 swap_with_parent(node_pointer p_nd, node_pointer p_parent);
259 bubble_to_top(node_pointer p_nd);
262 actual_erase_node(node_pointer p_nd);
265 clear_imp(node_pointer p_nd);
270 template<typename Pred>
274 #ifdef _GLIBCXX_DEBUG
276 assert_valid(const char* file, int line) const;
279 assert_node_consistent(const_node_pointer p_nd, bool single_link,
280 const char* file, int line) const;
283 size_under_node(const_node_pointer p_nd);
286 degree(const_node_pointer p_nd);
289 #ifdef PB_DS_LC_NS_HEAP_TRACE_
291 trace_node(const_node_pointer, size_type level);
295 node_pointer m_p_root;
300 #ifdef _GLIBCXX_DEBUG
302 assert_iterators(const char* file, int line) const;
305 assert_size(const char* file, int line) const;
308 size_from_node(const_node_pointer p_nd);
312 recursive_copy_node(const_node_pointer p_nd);
315 get_new_node_for_insert(const_reference r_val, false_type);
318 get_new_node_for_insert(const_reference r_val, true_type);
320 #ifdef PB_DS_LC_NS_HEAP_TRACE_
321 template<typename Metadata_>
323 trace_node_metadata(const_node_pointer p_nd, type_to_type<Metadata_>);
326 trace_node_metadata(const_node_pointer, type_to_type<null_left_child_next_sibling_heap_node_metadata>);
330 static node_allocator s_node_allocator;
332 static no_throw_copies_t s_no_throw_copies_ind;
335 #define PB_DS_ASSERT_VALID(X) \
336 _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);)
338 #define PB_DS_DEBUG_VERIFY(_Cond) \
339 _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \
340 _M_message(#_Cond" assertion from %1;:%2;") \
341 ._M_string(__FILE__)._M_integer(__LINE__) \
344 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp>
345 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp>
346 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp>
347 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp>
348 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp>
349 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp>
350 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp>
351 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp>
353 #undef PB_DS_DEBUG_VERIFY
354 #undef PB_DS_ASSERT_VALID
355 #undef PB_DS_CLASS_C_DEC
356 #undef PB_DS_CLASS_T_DEC
358 } // namespace detail
359 } // namespace __gnu_pbds