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
38 * Contains a redundant (binary counter).
49 #define PB_DS_CLASS_T_DEC \
50 template<typename Node, class Allocator>
52 #define PB_DS_CLASS_C_DEC \
55 template<typename Node
, class Allocator
>
59 typedef Allocator allocator_type
;
61 typedef typename
allocator_type::size_type size_type
;
66 typename
allocator_type::template rebind
<
71 typename
allocator_type::template rebind
<
72 node_pointer
>::other::pointer
76 typename
allocator_type::template rebind
<
77 node_pointer
>::other::const_pointer
82 max_entries
= sizeof(size_type
) << 3
86 typedef node_pointer entry
;
88 typedef const_entry_pointer const_iterator
;
93 rc(const PB_DS_CLASS_C_DEC
& other
);
96 swap(PB_DS_CLASS_C_DEC
& other
);
122 #ifdef _GLIBCXX_DEBUG
124 assert_valid() const;
127 #ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
133 node_pointer m_a_entries
[max_entries
];
135 size_type m_over_top
;
141 { _GLIBCXX_DEBUG_ONLY(assert_valid();) }
145 rc(const PB_DS_CLASS_C_DEC
& other
) : m_over_top(0)
146 { _GLIBCXX_DEBUG_ONLY(assert_valid();) }
151 swap(PB_DS_CLASS_C_DEC
& other
)
153 _GLIBCXX_DEBUG_ONLY(assert_valid();)
154 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
156 const size_type over_top
= std::max(m_over_top
, other
.m_over_top
);
158 for (size_type i
= 0; i
< over_top
; ++i
)
159 std::swap(m_a_entries
[i
], other
.m_a_entries
[i
]);
161 std::swap(m_over_top
, other
.m_over_top
);
162 _GLIBCXX_DEBUG_ONLY(assert_valid();)
163 _GLIBCXX_DEBUG_ONLY(other
.assert_valid();)
171 _GLIBCXX_DEBUG_ONLY(assert_valid();)
172 _GLIBCXX_DEBUG_ASSERT(m_over_top
< max_entries
);
173 m_a_entries
[m_over_top
++] = p_nd
;
174 _GLIBCXX_DEBUG_ONLY(assert_valid();)
182 _GLIBCXX_DEBUG_ONLY(assert_valid();)
183 _GLIBCXX_DEBUG_ASSERT(!empty());
185 _GLIBCXX_DEBUG_ONLY(assert_valid();)
189 inline typename
PB_DS_CLASS_C_DEC::node_pointer
193 _GLIBCXX_DEBUG_ONLY(assert_valid();)
194 _GLIBCXX_DEBUG_ASSERT(!empty());
195 return *(m_a_entries
+ m_over_top
- 1);
203 _GLIBCXX_DEBUG_ONLY(assert_valid();)
204 return m_over_top
== 0;
208 inline typename
PB_DS_CLASS_C_DEC::size_type
211 { return m_over_top
; }
218 _GLIBCXX_DEBUG_ONLY(assert_valid();)
220 _GLIBCXX_DEBUG_ONLY(assert_valid();)
224 const typename
PB_DS_CLASS_C_DEC::const_iterator
227 { return& m_a_entries
[0]; }
230 const typename
PB_DS_CLASS_C_DEC::const_iterator
233 { return& m_a_entries
[m_over_top
]; }
235 #ifdef _GLIBCXX_DEBUG
240 { _GLIBCXX_DEBUG_ASSERT(m_over_top
< max_entries
); }
243 #ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
249 std::cout
<< "rc" << std::endl
;
250 for (size_type i
= 0; i
< m_over_top
; ++i
)
251 std::cerr
<< m_a_entries
[i
] << std::endl
;
252 std::cout
<< std::endl
;
256 #undef PB_DS_CLASS_T_DEC
257 #undef PB_DS_CLASS_C_DEC
259 } // namespace detail
260 } // namespace __gnu_pbds