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 pairing_heap_.hpp
38 * Contains an implementation class for a pairing heap.
43 * Michael L. Fredman, Robert Sedgewick, Daniel Dominic Sleator,
44 * and Robert Endre Tarjan, The Pairing Heap:
45 * A New Form of Self-Adjusting Heap, Algorithmica, 1(1):111-129, 1986.
48 #include <ext/pb_ds/detail/cond_dealtor.hpp>
49 #include <ext/pb_ds/detail/type_utils.hpp>
50 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp>
51 #include <ext/pb_ds/detail/left_child_next_sibling_heap_/null_metadata.hpp>
52 #include <debug/debug.h>
59 #define PB_DS_CLASS_T_DEC \
60 template<typename Value_Type, class Cmp_Fn, class Allocator>
62 #define PB_DS_CLASS_C_DEC \
63 pairing_heap_<Value_Type, Cmp_Fn, Allocator>
66 #define PB_DS_BASE_C_DEC \
67 left_child_next_sibling_heap_< \
70 null_left_child_next_sibling_heap_node_metadata, \
74 #define PB_DS_BASE_C_DEC \
75 left_child_next_sibling_heap_< \
78 null_left_child_next_sibling_heap_node_metadata, \
83 * class description = "P4ri|\|g h3ap$">
85 template<typename Value_Type
, class Cmp_Fn
, class Allocator
>
86 class pairing_heap_
: public PB_DS_BASE_C_DEC
90 typedef PB_DS_BASE_C_DEC base_type
;
92 typedef typename
base_type::node_pointer 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
;
139 pairing_heap_(const Cmp_Fn
& r_cmp_fn
);
141 pairing_heap_(const PB_DS_CLASS_C_DEC
& other
);
144 swap(PB_DS_CLASS_C_DEC
& other
);
148 inline point_iterator
149 push(const_reference r_val
);
152 modify(point_iterator it
, const_reference r_new_val
);
154 inline const_reference
161 erase(point_iterator it
);
163 template<typename Pred
>
167 template<typename Pred
>
169 split(Pred pred
, PB_DS_CLASS_C_DEC
& other
);
172 join(PB_DS_CLASS_C_DEC
& other
);
176 template<typename It
>
178 copy_from_range(It first_it
, It last_it
);
180 #ifdef _GLIBCXX_DEBUG
182 assert_valid() const;
188 push_imp(node_pointer p_nd
);
191 join_node_children(node_pointer p_nd
);
194 forward_join(node_pointer p_nd
, node_pointer p_next
);
197 back_join(node_pointer p_nd
, node_pointer p_next
);
200 remove_node(node_pointer p_nd
);
204 #include <ext/pb_ds/detail/pairing_heap_/constructors_destructor_fn_imps.hpp>
205 #include <ext/pb_ds/detail/pairing_heap_/debug_fn_imps.hpp>
206 #include <ext/pb_ds/detail/pairing_heap_/find_fn_imps.hpp>
207 #include <ext/pb_ds/detail/pairing_heap_/insert_fn_imps.hpp>
208 #include <ext/pb_ds/detail/pairing_heap_/erase_fn_imps.hpp>
209 #include <ext/pb_ds/detail/pairing_heap_/split_join_fn_imps.hpp>
211 #undef PB_DS_CLASS_C_DEC
212 #undef PB_DS_CLASS_T_DEC
213 #undef PB_DS_BASE_C_DEC
215 } // namespace detail
216 } // namespace __gnu_pbds