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 thin_heap_.hpp
38 * Contains an implementation class for a thin heap.
41 #ifndef PB_DS_THIN_HEAP_HPP
42 #define PB_DS_THIN_HEAP_HPP
50 #include <ext/pb_ds/detail/cond_dealtor.hpp>
51 #include <ext/pb_ds/detail/type_utils.hpp>
52 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp>
53 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/null_metadata.hpp>
54 #include <debug/debug.h>
61 #define PB_DS_CLASS_T_DEC \
62 template<typename Value_Type, class Cmp_Fn, class Allocator>
64 #define PB_DS_CLASS_C_DEC \
65 thin_heap_<Value_Type, Cmp_Fn, Allocator>
68 #define PB_DS_BASE_C_DEC \
69 left_child_next_sibling_heap_<Value_Type, Cmp_Fn, \
70 typename Allocator::size_type, Allocator, true>
72 #define PB_DS_BASE_C_DEC \
73 left_child_next_sibling_heap_<Value_Type, Cmp_Fn, \
74 typename Allocator::size_type, Allocator>
78 * class description = "t|-|i|\| h34p">
80 template<typename Value_Type, class Cmp_Fn, class Allocator>
81 class thin_heap_ : public PB_DS_BASE_C_DEC
85 typedef PB_DS_BASE_C_DEC base_type;
88 typedef typename base_type::node node;
90 typedef typename base_type::node_pointer node_pointer;
92 typedef typename base_type::const_node_pointer const_node_pointer;
96 typedef typename Allocator::size_type size_type;
98 typedef typename Allocator::difference_type difference_type;
100 typedef Value_Type value_type;
103 typename Allocator::template rebind<
104 value_type>::other::pointer
108 typename Allocator::template rebind<
109 value_type>::other::const_pointer
113 typename Allocator::template rebind<
114 value_type>::other::reference
118 typename Allocator::template rebind<
119 value_type>::other::const_reference
123 typename PB_DS_BASE_C_DEC::const_point_iterator
124 const_point_iterator;
126 typedef typename PB_DS_BASE_C_DEC::point_iterator point_iterator;
128 typedef typename PB_DS_BASE_C_DEC::const_iterator const_iterator;
130 typedef typename PB_DS_BASE_C_DEC::iterator iterator;
132 typedef Cmp_Fn cmp_fn;
134 typedef Allocator allocator_type;
138 inline point_iterator
139 push(const_reference r_val);
142 modify(point_iterator it, const_reference r_new_val);
144 inline const_reference
151 erase(point_iterator it);
156 template<typename Pred>
160 template<typename Pred>
162 split(Pred pred, PB_DS_CLASS_C_DEC& other);
165 join(PB_DS_CLASS_C_DEC& other);
171 thin_heap_(const Cmp_Fn& r_cmp_fn);
173 thin_heap_(const PB_DS_CLASS_C_DEC& other);
176 swap(PB_DS_CLASS_C_DEC& other);
180 template<typename It>
182 copy_from_range(It first_it, It last_it);
184 #ifdef _GLIBCXX_DEBUG
186 assert_valid() const;
192 #ifdef PB_DS_THIN_HEAP_TRACE_
200 max_rank = (sizeof(size_type) << 4) + 2
209 update_max(node_pointer p_nd);
212 fix(node_pointer p_nd);
215 fix_root(node_pointer p_y);
218 fix_sibling_rank_1_unmarked(node_pointer p_y);
221 fix_sibling_rank_1_marked(node_pointer p_y);
224 fix_sibling_general_unmarked(node_pointer p_y);
227 fix_sibling_general_marked(node_pointer p_y);
230 fix_child(node_pointer p_y);
233 make_root(node_pointer p_nd);
236 make_root_and_link(node_pointer p_nd);
245 add_to_aux(node_pointer p_nd);
254 make_child_of(node_pointer p_nd, node_pointer p_new_parent);
257 remove_node(node_pointer p_nd);
260 join(node_pointer p_lhs, node_pointer p_rhs) const;
262 #ifdef _GLIBCXX_DEBUG
264 assert_node_consistent(const_node_pointer p_nd, bool root) const;
267 assert_aux_null() const;
271 node_pointer m_p_max;
273 node_pointer m_a_aux[max_rank];
278 num_distinct_rank_bounds = 48
281 // Taken from the SGI implementation; acknowledged in the docs.
282 static const std::size_t g_a_rank_bounds[num_distinct_rank_bounds] =
284 /* Dealing cards... */
325 /* 40 */ 141422324ul,
326 /* 41 */ 228826127ul,
327 /* 42 */ 370248451ul,
328 /* 43 */ 599074578ul,
329 /* 44 */ 969323029ul,
330 /* 45 */ 1568397607ul,
331 /* 46 */ 2537720636ul,
332 /* 47 */ 4106118243ul
333 /* Pot's good, let's play */
336 #include <ext/pb_ds/detail/thin_heap_/constructors_destructor_fn_imps.hpp>
337 #include <ext/pb_ds/detail/thin_heap_/debug_fn_imps.hpp>
338 #include <ext/pb_ds/detail/thin_heap_/trace_fn_imps.hpp>
339 #include <ext/pb_ds/detail/thin_heap_/find_fn_imps.hpp>
340 #include <ext/pb_ds/detail/thin_heap_/insert_fn_imps.hpp>
341 #include <ext/pb_ds/detail/thin_heap_/erase_fn_imps.hpp>
342 #include <ext/pb_ds/detail/thin_heap_/split_join_fn_imps.hpp>
344 #undef PB_DS_CLASS_C_DEC
345 #undef PB_DS_CLASS_T_DEC
346 #undef PB_DS_BASE_C_DEC
348 } // namespace detail
349 } // namespace __gnu_pbds