]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libstdc++/include/ext/pb_ds/detail/rc_binomial_heap_/rc_binomial_heap_.hpp
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / libstdc++ / include / ext / pb_ds / detail / rc_binomial_heap_ / rc_binomial_heap_.hpp
1 // -*- C++ -*-
2
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.
10
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.
15
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.
20
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.
30
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32
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.
41
42 /**
43  * @file rc_binomial_heap_.hpp
44  * Contains an implementation for rc_binomial_heap_.
45  */
46
47 /*
48  * Redundant-counter binomial heap.
49  */
50
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>
56
57 namespace pb_ds
58 {
59   namespace detail
60   {
61 #define PB_DS_CLASS_T_DEC \
62     template<typename Value_Type, class Cmp_Fn, class Allocator>
63
64 #define PB_DS_CLASS_C_DEC \
65     rc_binomial_heap_<Value_Type, Cmp_Fn, Allocator>
66
67 #define PB_DS_BASE_C_DEC \
68     binomial_heap_base_<Value_Type, Cmp_Fn, Allocator>
69
70 #define PB_DS_RC_C_DEC \
71     rc<typename PB_DS_BASE_C_DEC::node, Allocator>
72
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
78     {
79
80     private:
81       typedef PB_DS_BASE_C_DEC base_type;
82
83       typedef typename base_type::node_pointer node_pointer;
84
85       typedef typename base_type::const_node_pointer const_node_pointer;
86
87       typedef PB_DS_RC_C_DEC rc_t;
88
89     public:
90
91       typedef typename Allocator::size_type size_type;
92
93       typedef typename Allocator::difference_type difference_type;
94
95       typedef Value_Type value_type;
96
97       typedef typename base_type::pointer pointer;
98
99       typedef typename base_type::const_pointer const_pointer;
100
101       typedef typename base_type::reference reference;
102
103       typedef typename base_type::const_reference const_reference;
104
105       typedef typename base_type::const_point_iterator const_point_iterator;
106
107       typedef typename base_type::point_iterator point_iterator;
108
109       typedef typename base_type::const_iterator const_iterator;
110
111       typedef typename base_type::iterator iterator;
112
113       typedef typename base_type::cmp_fn cmp_fn;
114
115       typedef typename base_type::allocator allocator;
116
117     public:
118
119       rc_binomial_heap_();
120
121       rc_binomial_heap_(const Cmp_Fn& r_cmp_fn);
122
123       rc_binomial_heap_(const PB_DS_CLASS_C_DEC& other);
124
125       ~rc_binomial_heap_();
126
127       void
128       swap(PB_DS_CLASS_C_DEC& other);
129
130       inline point_iterator
131       push(const_reference r_val);
132
133       void
134       modify(point_iterator it, const_reference r_new_val);
135
136       inline void
137       pop();
138
139       void
140       erase(point_iterator it);
141
142       inline void
143       clear();
144
145       template<typename Pred>
146       size_type
147       erase_if(Pred pred);
148
149       template<typename Pred>
150       void
151       split(Pred pred, PB_DS_CLASS_C_DEC& other);
152
153       void
154       join(PB_DS_CLASS_C_DEC& other);
155
156 #ifdef _GLIBCXX_DEBUG
157       void
158       assert_valid() const;
159 #endif 
160
161 #ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
162       void
163       trace() const;
164 #endif 
165
166     private:
167
168       inline node_pointer
169       link_with_next_sibling(node_pointer p_nd);
170
171       void
172       make_0_exposed();
173
174       void
175       make_binomial_heap();
176
177 #ifdef _GLIBCXX_DEBUG
178       static const_node_pointer
179       next_2_pointer(const_node_pointer p_nd);
180
181       static const_node_pointer
182       next_after_0_pointer(const_node_pointer p_nd);
183 #endif 
184
185     private:
186       rc_t m_rc;
187     };
188
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>
195
196 #undef PB_DS_CLASS_C_DEC
197
198 #undef PB_DS_CLASS_T_DEC
199
200 #undef PB_DS_BASE_C_DEC
201
202 #undef PB_DS_RC_C_DEC
203   } // namespace detail
204 } // namespace pb_ds