Import gcc-4.4.1
[dragonfly.git] / contrib / gcc-4.4 / libstdc++-v3 / include / ext / pb_ds / detail / pairing_heap_ / pairing_heap_.hpp
blobe19bcb695bd8a9d0c77e4a391b4dd03abdd74e16
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
4 //
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
9 // version.
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
34 // warranty.
36 /**
37 * @file pairing_heap_.hpp
38 * Contains an implementation class for a pairing heap.
42 * 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>
54 namespace __gnu_pbds
56 namespace detail
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>
65 #ifdef _GLIBCXX_DEBUG
66 #define PB_DS_BASE_C_DEC \
67 left_child_next_sibling_heap_< \
68 Value_Type, \
69 Cmp_Fn, \
70 null_left_child_next_sibling_heap_node_metadata, \
71 Allocator, \
72 false>
73 #else
74 #define PB_DS_BASE_C_DEC \
75 left_child_next_sibling_heap_< \
76 Value_Type, \
77 Cmp_Fn, \
78 null_left_child_next_sibling_heap_node_metadata, \
79 Allocator>
80 #endif
82 /**
83 * class description = "P4ri|\|g h3ap$">
84 **/
85 template<typename Value_Type, class Cmp_Fn, class Allocator>
86 class pairing_heap_ : public PB_DS_BASE_C_DEC
89 private:
90 typedef PB_DS_BASE_C_DEC base_type;
92 typedef typename base_type::node_pointer node_pointer;
94 public:
96 typedef typename Allocator::size_type size_type;
98 typedef typename Allocator::difference_type difference_type;
100 typedef Value_Type value_type;
102 typedef
103 typename Allocator::template rebind<
104 value_type>::other::pointer
105 pointer;
107 typedef
108 typename Allocator::template rebind<
109 value_type>::other::const_pointer
110 const_pointer;
112 typedef
113 typename Allocator::template rebind<
114 value_type>::other::reference
115 reference;
117 typedef
118 typename Allocator::template rebind<
119 value_type>::other::const_reference
120 const_reference;
122 typedef
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;
137 pairing_heap_();
139 pairing_heap_(const Cmp_Fn& r_cmp_fn);
141 pairing_heap_(const PB_DS_CLASS_C_DEC& other);
143 void
144 swap(PB_DS_CLASS_C_DEC& other);
146 ~pairing_heap_();
148 inline point_iterator
149 push(const_reference r_val);
151 void
152 modify(point_iterator it, const_reference r_new_val);
154 inline const_reference
155 top() const;
157 void
158 pop();
160 void
161 erase(point_iterator it);
163 template<typename Pred>
164 size_type
165 erase_if(Pred pred);
167 template<typename Pred>
168 void
169 split(Pred pred, PB_DS_CLASS_C_DEC& other);
171 void
172 join(PB_DS_CLASS_C_DEC& other);
174 protected:
176 template<typename It>
177 void
178 copy_from_range(It first_it, It last_it);
180 #ifdef _GLIBCXX_DEBUG
181 void
182 assert_valid() const;
183 #endif
185 private:
187 inline void
188 push_imp(node_pointer p_nd);
190 node_pointer
191 join_node_children(node_pointer p_nd);
193 node_pointer
194 forward_join(node_pointer p_nd, node_pointer p_next);
196 node_pointer
197 back_join(node_pointer p_nd, node_pointer p_next);
199 void
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