3 // Copyright (C) 2005, 2006, 2009 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;
279 assert_node_consistent(const_node_pointer p_nd
, bool single_link
) const;
282 size_under_node(const_node_pointer p_nd
);
285 degree(const_node_pointer p_nd
);
288 #ifdef PB_DS_LC_NS_HEAP_TRACE_
290 trace_node(const_node_pointer
, size_type level
);
294 node_pointer m_p_root
;
299 #ifdef _GLIBCXX_DEBUG
301 assert_iterators() const;
307 size_from_node(const_node_pointer p_nd
);
311 recursive_copy_node(const_node_pointer p_nd
);
314 get_new_node_for_insert(const_reference r_val
, false_type
);
317 get_new_node_for_insert(const_reference r_val
, true_type
);
319 #ifdef PB_DS_LC_NS_HEAP_TRACE_
320 template<typename Metadata_
>
322 trace_node_metadata(const_node_pointer p_nd
, type_to_type
<Metadata_
>);
325 trace_node_metadata(const_node_pointer
, type_to_type
<null_left_child_next_sibling_heap_node_metadata
>);
329 static node_allocator s_node_allocator
;
331 static no_throw_copies_t s_no_throw_copies_ind
;
334 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp>
335 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp>
336 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp>
337 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp>
338 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp>
339 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp>
340 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp>
341 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp>
343 #undef PB_DS_CLASS_C_DEC
344 #undef PB_DS_CLASS_T_DEC
346 } // namespace detail
347 } // namespace __gnu_pbds