Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / pb_ds / detail / rc_binomial_heap_ / rc_binomial_heap_.hpp
blob5b4a3b4122fc001f22c81fed15e2bcdfd302507c
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 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 2, 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 // 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
29 // Public License.
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
40 // warranty.
42 /**
43 * @file rc_binomial_heap_.hpp
44 * Contains an implementation for rc_binomial_heap_.
48 * Redundant-counter binomial heap.
51 #include <ext/pb_ds/detail/cond_dealtor.hpp>
52 #include <ext/pb_ds/detail/type_utils.hpp>
53 #include <ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp>
54 #include <ext/pb_ds/detail/rc_binomial_heap_/rc.hpp>
55 #include <debug/debug.h>
57 namespace __gnu_pbds
59 namespace detail
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 rc_binomial_heap_<Value_Type, Cmp_Fn, Allocator>
67 #define PB_DS_BASE_C_DEC \
68 binomial_heap_base_<Value_Type, Cmp_Fn, Allocator>
70 #define PB_DS_RC_C_DEC \
71 rc<typename PB_DS_BASE_C_DEC::node, Allocator>
73 /**
74 * class description = "8y|\|0|\/|i41 h34p 74813">
75 **/
76 template<typename Value_Type, class Cmp_Fn, class Allocator>
77 class rc_binomial_heap_ : public PB_DS_BASE_C_DEC
80 private:
81 typedef PB_DS_BASE_C_DEC base_type;
83 typedef typename base_type::node_pointer node_pointer;
85 typedef typename base_type::const_node_pointer const_node_pointer;
87 typedef PB_DS_RC_C_DEC rc_t;
89 public:
91 typedef typename Allocator::size_type size_type;
93 typedef typename Allocator::difference_type difference_type;
95 typedef Value_Type value_type;
97 typedef typename base_type::pointer pointer;
99 typedef typename base_type::const_pointer const_pointer;
101 typedef typename base_type::reference reference;
103 typedef typename base_type::const_reference const_reference;
105 typedef typename base_type::const_point_iterator const_point_iterator;
107 typedef typename base_type::point_iterator point_iterator;
109 typedef typename base_type::const_iterator const_iterator;
111 typedef typename base_type::iterator iterator;
113 typedef typename base_type::cmp_fn cmp_fn;
115 typedef typename base_type::allocator allocator;
117 public:
119 rc_binomial_heap_();
121 rc_binomial_heap_(const Cmp_Fn& r_cmp_fn);
123 rc_binomial_heap_(const PB_DS_CLASS_C_DEC& other);
125 ~rc_binomial_heap_();
127 void
128 swap(PB_DS_CLASS_C_DEC& other);
130 inline point_iterator
131 push(const_reference r_val);
133 void
134 modify(point_iterator it, const_reference r_new_val);
136 inline void
137 pop();
139 void
140 erase(point_iterator it);
142 inline void
143 clear();
145 template<typename Pred>
146 size_type
147 erase_if(Pred pred);
149 template<typename Pred>
150 void
151 split(Pred pred, PB_DS_CLASS_C_DEC& other);
153 void
154 join(PB_DS_CLASS_C_DEC& other);
156 #ifdef _GLIBCXX_DEBUG
157 void
158 assert_valid() const;
159 #endif
161 #ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
162 void
163 trace() const;
164 #endif
166 private:
168 inline node_pointer
169 link_with_next_sibling(node_pointer p_nd);
171 void
172 make_0_exposed();
174 void
175 make_binomial_heap();
177 #ifdef _GLIBCXX_DEBUG
178 static const_node_pointer
179 next_2_pointer(const_node_pointer p_nd);
181 static const_node_pointer
182 next_after_0_pointer(const_node_pointer p_nd);
183 #endif
185 private:
186 rc_t m_rc;
189 #include <ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp>
190 #include <ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp>
191 #include <ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp>
192 #include <ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp>
193 #include <ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp>
194 #include <ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp>
196 #undef PB_DS_CLASS_C_DEC
198 #undef PB_DS_CLASS_T_DEC
200 #undef PB_DS_BASE_C_DEC
202 #undef PB_DS_RC_C_DEC
203 } // namespace detail
204 } // namespace __gnu_pbds