3 // Copyright (C) 2005-2014 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 binomial_heap_base_/binomial_heap_base_.hpp
38 * Contains an implementation class for a base of binomial heaps.
41 #ifndef PB_DS_BINOMIAL_HEAP_BASE_HPP
42 #define PB_DS_BINOMIAL_HEAP_BASE_HPP
46 * Vuillemin J is the mastah.
50 #include <debug/debug.h>
51 #include <ext/pb_ds/detail/cond_dealtor.hpp>
52 #include <ext/pb_ds/detail/type_utils.hpp>
53 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp>
59 #define PB_DS_CLASS_T_DEC \
60 template<typename Value_Type, typename Cmp_Fn, typename _Alloc>
62 #define PB_DS_CLASS_C_DEC \
63 binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>
66 #define PB_DS_B_HEAP_BASE \
67 left_child_next_sibling_heap<Value_Type, Cmp_Fn, \
68 typename _Alloc::size_type, _Alloc, false>
70 #define PB_DS_B_HEAP_BASE \
71 left_child_next_sibling_heap<Value_Type, Cmp_Fn, \
72 typename _Alloc::size_type, _Alloc>
75 /// Base class for binomial heap.
76 template<typename Value_Type, typename Cmp_Fn, typename _Alloc>
77 class binomial_heap_base
78 : public PB_DS_B_HEAP_BASE
81 typedef typename _Alloc::template rebind<Value_Type>::other __rebind_v;
82 typedef PB_DS_B_HEAP_BASE base_type;
85 typedef typename base_type::node node;
86 typedef typename base_type::node_pointer node_pointer;
87 typedef typename base_type::node_const_pointer node_const_pointer;
90 typedef Value_Type value_type;
91 typedef Cmp_Fn cmp_fn;
92 typedef _Alloc allocator_type;
93 typedef typename _Alloc::size_type size_type;
94 typedef typename _Alloc::difference_type difference_type;
96 typedef typename __rebind_v::pointer pointer;
97 typedef typename __rebind_v::const_pointer const_pointer;
98 typedef typename __rebind_v::reference reference;
99 typedef typename __rebind_v::const_reference const_reference;
101 typedef typename base_type::point_const_iterator point_const_iterator;
102 typedef typename base_type::point_iterator point_iterator;
103 typedef typename base_type::const_iterator const_iterator;
104 typedef typename base_type::iterator iterator;
108 inline point_iterator
109 push(const_reference);
112 modify(point_iterator, const_reference);
114 inline const_reference
121 erase(point_iterator);
126 template<typename Pred>
130 template<typename Pred>
132 split(Pred, PB_DS_CLASS_C_DEC&);
135 join(PB_DS_CLASS_C_DEC&);
139 binomial_heap_base();
141 binomial_heap_base(const Cmp_Fn&);
143 binomial_heap_base(const PB_DS_CLASS_C_DEC&);
146 swap(PB_DS_CLASS_C_DEC&);
148 ~binomial_heap_base();
150 template<typename It>
152 copy_from_range(It, It);
157 #ifdef _GLIBCXX_DEBUG
159 assert_valid(bool, const char*, int) const;
162 assert_max(const char*, int) const;
168 fix(node_pointer) const;
171 insert_node(node_pointer);
174 remove_parentless_node(node_pointer);
177 join(node_pointer, node_pointer) const;
179 #ifdef _GLIBCXX_DEBUG
181 assert_node_consistent(node_const_pointer, bool, bool,
182 const char*, int) const;
186 node_pointer m_p_max;
189 #define PB_DS_ASSERT_VALID_COND(X, _StrictlyBinomial) \
190 _GLIBCXX_DEBUG_ONLY(X.assert_valid(_StrictlyBinomial,__FILE__, __LINE__);)
192 #define PB_DS_ASSERT_BASE_NODE_CONSISTENT(_Node, _Bool) \
193 _GLIBCXX_DEBUG_ONLY(base_type::assert_node_consistent(_Node, _Bool, \
194 __FILE__, __LINE__);)
196 #include <ext/pb_ds/detail/binomial_heap_base_/constructors_destructor_fn_imps.hpp>
197 #include <ext/pb_ds/detail/binomial_heap_base_/debug_fn_imps.hpp>
198 #include <ext/pb_ds/detail/binomial_heap_base_/find_fn_imps.hpp>
199 #include <ext/pb_ds/detail/binomial_heap_base_/insert_fn_imps.hpp>
200 #include <ext/pb_ds/detail/binomial_heap_base_/erase_fn_imps.hpp>
201 #include <ext/pb_ds/detail/binomial_heap_base_/split_join_fn_imps.hpp>
203 #undef PB_DS_ASSERT_BASE_NODE_CONSISTENT
204 #undef PB_DS_ASSERT_VALID_COND
205 #undef PB_DS_CLASS_C_DEC
206 #undef PB_DS_CLASS_T_DEC
207 #undef PB_DS_B_HEAP_BASE
208 } // namespace detail
209 } // namespace __gnu_pbds