3 // Copyright (C) 2005, 2006 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 2, 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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file left_child_next_sibling_heap_.hpp
44 * Contains an implementation class for a basic heap.
47 #ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP
48 #define PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP
55 #include <ext/pb_ds/detail/cond_dealtor.hpp>
56 #include <ext/pb_ds/detail/type_utils.hpp>
57 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/node.hpp>
58 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/const_point_iterator.hpp>
59 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/const_iterator.hpp>
60 #ifdef PB_DS_LC_NS_HEAP_TRACE_
62 #endif // #ifdef PB_DS_LC_NS_HEAP_TRACE_
69 #ifdef PB_DS_LC_NS_HEAP_DEBUG_
70 #define PB_DS_DBG_ASSERT(X) assert(X)
71 #define PB_DS_DBG_VERIFY(X) assert(X)
72 #define PB_DS_DBG_ONLY(X) X
73 #else // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
74 #define PB_DS_DBG_ASSERT(X)
75 #define PB_DS_DBG_VERIFY(X) {if((X)==0);}
76 #define PB_DS_DBG_ONLY(X) ;
77 #endif // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
79 #ifdef PB_DS_LC_NS_HEAP_DEBUG_
80 #define PB_DS_CLASS_T_DEC \
82 typename Value_Type, \
84 typename Node_Metadata, \
86 bool Single_Link_Roots>
87 #else // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
88 #define PB_DS_CLASS_T_DEC \
90 typename Value_Type, \
92 typename Node_Metadata, \
94 #endif // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
96 #ifdef PB_DS_LC_NS_HEAP_DEBUG_
97 #define PB_DS_CLASS_C_DEC \
98 left_child_next_sibling_heap_< \
104 #else // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
105 #define PB_DS_CLASS_C_DEC \
106 left_child_next_sibling_heap_< \
111 #endif // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
114 * class description = "Base class for some types of h3ap$">
116 #ifdef PB_DS_LC_NS_HEAP_DEBUG_
117 template<typename Value_Type,
119 typename Node_Metadata,
121 bool Single_Link_Roots>
122 #else // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
123 template<typename Value_Type,
125 typename Node_Metadata,
127 #endif // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
128 class left_child_next_sibling_heap_ : public Cmp_Fn
133 typename Allocator::template rebind<
134 left_child_next_sibling_heap_node_<
140 typedef typename node_allocator::value_type node;
142 typedef typename node_allocator::pointer node_pointer;
144 typedef typename node_allocator::const_pointer const_node_pointer;
146 typedef Node_Metadata node_metadata;
148 typedef std::pair< node_pointer, node_pointer> node_pointer_pair;
151 typedef cond_dealtor< node, Allocator> cond_dealtor_t;
155 simple_value = is_simple<
159 typedef integral_constant<int, simple_value> no_throw_copies_t;
163 typedef typename Allocator::size_type size_type;
165 typedef typename Allocator::difference_type difference_type;
167 typedef Value_Type value_type;
170 typename Allocator::template rebind<
171 value_type>::other::pointer
175 typename Allocator::template rebind<
176 value_type>::other::const_pointer
180 typename Allocator::template rebind<
181 value_type>::other::reference
185 typename Allocator::template rebind<
186 value_type>::other::const_reference
190 left_child_next_sibling_heap_node_const_point_iterator_<
193 const_point_iterator;
195 typedef const_point_iterator point_iterator;
198 left_child_next_sibling_heap_const_iterator_<
203 typedef const_iterator iterator;
205 typedef Cmp_Fn cmp_fn;
207 typedef Allocator allocator;
211 left_child_next_sibling_heap_();
213 left_child_next_sibling_heap_(const Cmp_Fn& r_cmp_fn);
215 left_child_next_sibling_heap_(const PB_DS_CLASS_C_DEC& other);
218 swap(PB_DS_CLASS_C_DEC& other);
220 ~left_child_next_sibling_heap_();
240 inline const_iterator
246 inline const_iterator
252 #ifdef PB_DS_LC_NS_HEAP_TRACE_
257 #endif // #ifdef PB_DS_LC_NS_HEAP_TRACE_
262 get_new_node_for_insert(const_reference r_val);
265 make_child_of(node_pointer p_nd, node_pointer p_new_parent);
268 value_swap(PB_DS_CLASS_C_DEC& other);
270 inline static node_pointer
271 parent(node_pointer p_nd);
274 swap_with_parent(node_pointer p_nd, node_pointer p_parent);
277 bubble_to_top(node_pointer p_nd);
280 actual_erase_node(node_pointer p_nd);
283 clear_imp(node_pointer p_nd);
288 template<typename Pred>
292 #ifdef PB_DS_LC_NS_HEAP_DEBUG_
295 assert_valid() const;
298 assert_node_consistent(const_node_pointer p_nd, bool single_link) const;
301 size_under_node(const_node_pointer p_nd);
304 degree(const_node_pointer p_nd);
306 #endif // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
308 #ifdef PB_DS_LC_NS_HEAP_TRACE_
311 trace_node(const_node_pointer, size_type level);
313 #endif // #ifdef PB_DS_LC_NS_HEAP_TRACE_
316 node_pointer m_p_root;
321 #ifdef PB_DS_LC_NS_HEAP_DEBUG_
324 assert_iterators() const;
330 size_from_node(const_node_pointer p_nd);
332 #endif // #ifdef PB_DS_LC_NS_HEAP_DEBUG_
335 recursive_copy_node(const_node_pointer p_nd);
338 get_new_node_for_insert(const_reference r_val, false_type);
341 get_new_node_for_insert(const_reference r_val, true_type);
343 #ifdef PB_DS_LC_NS_HEAP_TRACE_
345 template<typename Metadata_>
347 trace_node_metadata(const_node_pointer p_nd, type_to_type<Metadata_>);
350 trace_node_metadata(const_node_pointer, type_to_type<null_left_child_next_sibling_heap_node_metadata>);
352 #endif // #ifdef PB_DS_LC_NS_HEAP_TRACE_
355 static node_allocator s_node_allocator;
357 static no_throw_copies_t s_no_throw_copies_ind;
360 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp>
361 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp>
362 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp>
363 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp>
364 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp>
365 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp>
366 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp>
367 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp>
369 #undef PB_DS_CLASS_C_DEC
371 #undef PB_DS_CLASS_T_DEC
373 #undef PB_DS_DBG_ASSERT
374 #undef PB_DS_DBG_VERIFY
375 #undef PB_DS_DBG_ONLY
377 } // namespace detail
380 #endif // #ifndef PB_DS_LEFT_CHILD_NEXT_SIBLING_HEAP_HPP