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_
63 #include <debug/debug.h>
71 #define PB_DS_CLASS_T_DEC \
73 typename Value_Type, \
75 typename Node_Metadata, \
77 bool Single_Link_Roots>
79 #define PB_DS_CLASS_T_DEC \
81 typename Value_Type, \
83 typename Node_Metadata, \
88 #define PB_DS_CLASS_C_DEC \
89 left_child_next_sibling_heap_< \
96 #define PB_DS_CLASS_C_DEC \
97 left_child_next_sibling_heap_< \
105 * class description = "Base class for some types of h3ap$">
107 #ifdef _GLIBCXX_DEBUG
108 template<typename Value_Type,
110 typename Node_Metadata,
112 bool Single_Link_Roots>
114 template<typename Value_Type,
116 typename Node_Metadata,
119 class left_child_next_sibling_heap_ : public Cmp_Fn
124 typename Allocator::template rebind<
125 left_child_next_sibling_heap_node_<
131 typedef typename node_allocator::value_type node;
133 typedef typename node_allocator::pointer node_pointer;
135 typedef typename node_allocator::const_pointer const_node_pointer;
137 typedef Node_Metadata node_metadata;
139 typedef std::pair< node_pointer, node_pointer> node_pointer_pair;
142 typedef cond_dealtor< node, Allocator> cond_dealtor_t;
146 simple_value = is_simple<Value_Type>::value
149 typedef integral_constant<int, simple_value> no_throw_copies_t;
153 typedef typename Allocator::size_type size_type;
155 typedef typename Allocator::difference_type difference_type;
157 typedef Value_Type value_type;
160 typename Allocator::template rebind<
161 value_type>::other::pointer
165 typename Allocator::template rebind<
166 value_type>::other::const_pointer
170 typename Allocator::template rebind<
171 value_type>::other::reference
175 typename Allocator::template rebind<
176 value_type>::other::const_reference
180 left_child_next_sibling_heap_node_const_point_iterator_<
183 const_point_iterator;
185 typedef const_point_iterator point_iterator;
188 left_child_next_sibling_heap_const_iterator_<
193 typedef const_iterator iterator;
195 typedef Cmp_Fn cmp_fn;
197 typedef Allocator allocator;
201 left_child_next_sibling_heap_();
203 left_child_next_sibling_heap_(const Cmp_Fn& r_cmp_fn);
205 left_child_next_sibling_heap_(const PB_DS_CLASS_C_DEC& other);
208 swap(PB_DS_CLASS_C_DEC& other);
210 ~left_child_next_sibling_heap_();
230 inline const_iterator
236 inline const_iterator
242 #ifdef PB_DS_LC_NS_HEAP_TRACE_
250 get_new_node_for_insert(const_reference r_val);
253 make_child_of(node_pointer p_nd, node_pointer p_new_parent);
256 value_swap(PB_DS_CLASS_C_DEC& other);
258 inline static node_pointer
259 parent(node_pointer p_nd);
262 swap_with_parent(node_pointer p_nd, node_pointer p_parent);
265 bubble_to_top(node_pointer p_nd);
268 actual_erase_node(node_pointer p_nd);
271 clear_imp(node_pointer p_nd);
276 template<typename Pred>
280 #ifdef _GLIBCXX_DEBUG
282 assert_valid() const;
285 assert_node_consistent(const_node_pointer p_nd, bool single_link) const;
288 size_under_node(const_node_pointer p_nd);
291 degree(const_node_pointer p_nd);
294 #ifdef PB_DS_LC_NS_HEAP_TRACE_
296 trace_node(const_node_pointer, size_type level);
300 node_pointer m_p_root;
305 #ifdef _GLIBCXX_DEBUG
307 assert_iterators() const;
313 size_from_node(const_node_pointer p_nd);
317 recursive_copy_node(const_node_pointer p_nd);
320 get_new_node_for_insert(const_reference r_val, false_type);
323 get_new_node_for_insert(const_reference r_val, true_type);
325 #ifdef PB_DS_LC_NS_HEAP_TRACE_
326 template<typename Metadata_>
328 trace_node_metadata(const_node_pointer p_nd, type_to_type<Metadata_>);
331 trace_node_metadata(const_node_pointer, type_to_type<null_left_child_next_sibling_heap_node_metadata>);
335 static node_allocator s_node_allocator;
337 static no_throw_copies_t s_no_throw_copies_ind;
340 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/constructors_destructor_fn_imps.hpp>
341 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/iterators_fn_imps.hpp>
342 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/debug_fn_imps.hpp>
343 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/trace_fn_imps.hpp>
344 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/insert_fn_imps.hpp>
345 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/erase_fn_imps.hpp>
346 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/info_fn_imps.hpp>
347 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/policy_access_fn_imps.hpp>
349 #undef PB_DS_CLASS_C_DEC
350 #undef PB_DS_CLASS_T_DEC
352 } // namespace detail
353 } // namespace __gnu_pbds