]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
85ec4feb | 3 | // Copyright (C) 2005-2018 Free Software Foundation, Inc. |
4569a895 AT |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
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 | ||
748086b7 JJ |
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. | |
4569a895 | 19 | |
748086b7 JJ |
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/>. | |
4569a895 AT |
24 | |
25 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
26 | ||
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. | |
35 | ||
36 | /** | |
a345e45d BK |
37 | * @file rc_binomial_heap_/rc_binomial_heap_.hpp |
38 | * Contains an implementation for redundant-counter binomial heap. | |
4569a895 AT |
39 | */ |
40 | ||
4569a895 AT |
41 | #include <ext/pb_ds/detail/cond_dealtor.hpp> |
42 | #include <ext/pb_ds/detail/type_utils.hpp> | |
43 | #include <ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp> | |
44 | #include <ext/pb_ds/detail/rc_binomial_heap_/rc.hpp> | |
47bea7b8 | 45 | #include <debug/debug.h> |
4569a895 | 46 | |
5e11f978 | 47 | namespace __gnu_pbds |
4569a895 AT |
48 | { |
49 | namespace detail | |
50 | { | |
47bea7b8 | 51 | #define PB_DS_CLASS_T_DEC \ |
a345e45d | 52 | template<typename Value_Type, typename Cmp_Fn, typename _Alloc> |
4569a895 | 53 | |
47bea7b8 | 54 | #define PB_DS_CLASS_C_DEC \ |
a345e45d | 55 | rc_binomial_heap<Value_Type, Cmp_Fn, _Alloc> |
4569a895 | 56 | |
47bea7b8 | 57 | #define PB_DS_RC_C_DEC \ |
a345e45d | 58 | rc<typename binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>::node, _Alloc> |
4569a895 | 59 | |
30a96b3b BK |
60 | /** |
61 | * Redundant-counter binomial heap. | |
62 | * | |
63 | * @ingroup heap-detail | |
64 | */ | |
a345e45d BK |
65 | template<typename Value_Type, typename Cmp_Fn, typename _Alloc> |
66 | class rc_binomial_heap | |
67 | : public binomial_heap_base<Value_Type, Cmp_Fn, _Alloc> | |
4569a895 | 68 | { |
4569a895 | 69 | private: |
a345e45d BK |
70 | typedef binomial_heap_base<Value_Type, Cmp_Fn, _Alloc> |
71 | base_type; | |
72 | typedef typename base_type::node_pointer node_pointer; | |
73 | typedef typename base_type::node_const_pointer node_const_pointer; | |
74 | typedef PB_DS_RC_C_DEC rc_t; | |
4569a895 AT |
75 | |
76 | public: | |
a345e45d BK |
77 | typedef Value_Type value_type; |
78 | typedef typename _Alloc::size_type size_type; | |
79 | typedef typename _Alloc::difference_type difference_type; | |
80 | typedef typename base_type::pointer pointer; | |
81 | typedef typename base_type::const_pointer const_pointer; | |
82 | typedef typename base_type::reference reference; | |
83 | typedef typename base_type::const_reference const_reference; | |
84 | typedef typename base_type::point_const_iterator point_const_iterator; | |
85 | typedef typename base_type::point_iterator point_iterator; | |
86 | typedef typename base_type::const_iterator const_iterator; | |
87 | typedef typename base_type::iterator iterator; | |
88 | typedef typename base_type::cmp_fn cmp_fn; | |
89 | typedef typename base_type::allocator_type allocator_type; | |
4569a895 | 90 | |
a345e45d | 91 | rc_binomial_heap(); |
4569a895 | 92 | |
a345e45d | 93 | rc_binomial_heap(const Cmp_Fn&); |
4569a895 | 94 | |
a345e45d | 95 | rc_binomial_heap(const PB_DS_CLASS_C_DEC&); |
4569a895 | 96 | |
a345e45d | 97 | ~rc_binomial_heap(); |
4569a895 AT |
98 | |
99 | void | |
a345e45d | 100 | swap(PB_DS_CLASS_C_DEC&); |
4569a895 AT |
101 | |
102 | inline point_iterator | |
a345e45d | 103 | push(const_reference); |
4569a895 AT |
104 | |
105 | void | |
a345e45d | 106 | modify(point_iterator, const_reference); |
4569a895 AT |
107 | |
108 | inline void | |
109 | pop(); | |
110 | ||
111 | void | |
a345e45d | 112 | erase(point_iterator); |
4569a895 AT |
113 | |
114 | inline void | |
115 | clear(); | |
116 | ||
117 | template<typename Pred> | |
118 | size_type | |
a345e45d | 119 | erase_if(Pred); |
4569a895 AT |
120 | |
121 | template<typename Pred> | |
122 | void | |
a345e45d | 123 | split(Pred, PB_DS_CLASS_C_DEC&); |
4569a895 AT |
124 | |
125 | void | |
a345e45d | 126 | join(PB_DS_CLASS_C_DEC&); |
4569a895 | 127 | |
47bea7b8 | 128 | #ifdef _GLIBCXX_DEBUG |
4569a895 | 129 | void |
a345e45d BK |
130 | assert_valid(const char*, int) const; |
131 | #endif | |
4569a895 AT |
132 | |
133 | #ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_ | |
4569a895 AT |
134 | void |
135 | trace() const; | |
a345e45d | 136 | #endif |
4569a895 AT |
137 | |
138 | private: | |
139 | ||
140 | inline node_pointer | |
a345e45d | 141 | link_with_next_sibling(node_pointer); |
4569a895 AT |
142 | |
143 | void | |
144 | make_0_exposed(); | |
145 | ||
146 | void | |
147 | make_binomial_heap(); | |
148 | ||
47bea7b8 | 149 | #ifdef _GLIBCXX_DEBUG |
a345e45d BK |
150 | static node_const_pointer |
151 | next_2_pointer(node_const_pointer); | |
4569a895 | 152 | |
a345e45d BK |
153 | static node_const_pointer |
154 | next_after_0_pointer(node_const_pointer); | |
155 | #endif | |
4569a895 | 156 | |
a345e45d | 157 | rc_t m_rc; |
4569a895 AT |
158 | }; |
159 | ||
160 | #include <ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp> | |
161 | #include <ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp> | |
162 | #include <ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp> | |
163 | #include <ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp> | |
164 | #include <ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp> | |
165 | #include <ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp> | |
166 | ||
167 | #undef PB_DS_CLASS_C_DEC | |
4569a895 | 168 | #undef PB_DS_CLASS_T_DEC |
4569a895 | 169 | #undef PB_DS_RC_C_DEC |
4569a895 | 170 | } // namespace detail |
5e11f978 | 171 | } // namespace __gnu_pbds |