• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2011.09/arm-none-eabi/include/c++/4.6.1/ext/pb_ds/detail/binomial_heap_base_/
1// -*- C++ -*-
2
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.
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// 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.
19
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/>.
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/**
37 * @file binomial_heap_base_.hpp
38 * Contains an implementation class for a base of binomial heaps.
39 */
40
41#ifndef PB_DS_BINOMIAL_HEAP_BASE_HPP
42#define PB_DS_BINOMIAL_HEAP_BASE_HPP
43
44/*
45 * Binomial heap base.
46 * Vuillemin J is the mastah.
47 * Modified from CLRS.
48 */
49
50#include <debug/debug.h>
51#include <ext/pb_ds/detail/cond_dealtor.hpp>
52#include <ext/pb_ds/detail/type_utils.hpp>
53#include <ext/pb_ds/detail/left_child_next_sibling_heap_/left_child_next_sibling_heap_.hpp>
54#include <ext/pb_ds/detail/left_child_next_sibling_heap_/null_metadata.hpp>
55
56namespace __gnu_pbds
57{
58  namespace detail
59  {
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    binomial_heap_base_<Value_Type, Cmp_Fn, Allocator>
66
67#ifdef _GLIBCXX_DEBUG
68#define PB_DS_BASE_C_DEC \
69    left_child_next_sibling_heap_<Value_Type, Cmp_Fn, \
70				  typename Allocator::size_type, \
71				  Allocator, false>
72#else
73#define PB_DS_BASE_C_DEC \
74    left_child_next_sibling_heap_<Value_Type, Cmp_Fn,	\
75				typename Allocator::size_type, Allocator>
76#endif
77
78    /**
79     * class description = "8y|\|0|\/|i41 h34p 74813">
80     **/
81    template<typename Value_Type, class Cmp_Fn, class Allocator>
82    class binomial_heap_base_ : public PB_DS_BASE_C_DEC
83    {
84
85    private:
86      typedef PB_DS_BASE_C_DEC base_type;
87
88    protected:
89      typedef typename base_type::node node;
90
91      typedef typename base_type::node_pointer node_pointer;
92
93      typedef typename base_type::const_node_pointer const_node_pointer;
94
95    public:
96
97      typedef typename Allocator::size_type size_type;
98
99      typedef typename Allocator::difference_type difference_type;
100
101      typedef Value_Type value_type;
102
103      typedef
104      typename Allocator::template rebind<
105	value_type>::other::pointer
106      pointer;
107
108      typedef
109      typename Allocator::template rebind<
110	value_type>::other::const_pointer
111      const_pointer;
112
113      typedef
114      typename Allocator::template rebind<
115	value_type>::other::reference
116      reference;
117
118      typedef
119      typename Allocator::template rebind<
120	value_type>::other::const_reference
121      const_reference;
122
123      typedef
124      typename PB_DS_BASE_C_DEC::const_point_iterator
125      const_point_iterator;
126
127      typedef typename PB_DS_BASE_C_DEC::point_iterator point_iterator;
128
129      typedef typename PB_DS_BASE_C_DEC::const_iterator const_iterator;
130
131      typedef typename PB_DS_BASE_C_DEC::iterator iterator;
132
133      typedef Cmp_Fn cmp_fn;
134
135      typedef Allocator allocator_type;
136
137    public:
138
139      inline point_iterator
140      push(const_reference r_val);
141
142      void
143      modify(point_iterator it, const_reference r_new_val);
144
145      inline const_reference
146      top() const;
147
148      void
149      pop();
150
151      void
152      erase(point_iterator it);
153
154      inline void
155      clear();
156
157      template<typename Pred>
158      size_type
159      erase_if(Pred pred);
160
161      template<typename Pred>
162      void
163      split(Pred pred, PB_DS_CLASS_C_DEC& other);
164
165      void
166      join(PB_DS_CLASS_C_DEC& other);
167
168    protected:
169
170      binomial_heap_base_();
171
172      binomial_heap_base_(const Cmp_Fn& r_cmp_fn);
173
174      binomial_heap_base_(const PB_DS_CLASS_C_DEC& other);
175
176      void
177      swap(PB_DS_CLASS_C_DEC& other);
178
179      ~binomial_heap_base_();
180
181      template<typename It>
182      void
183      copy_from_range(It first_it, It last_it);
184
185      inline void
186      find_max();
187
188#ifdef _GLIBCXX_DEBUG
189      void
190      assert_valid(bool strictly_binomial) const;
191
192      void
193      assert_max() const;
194#endif
195
196    private:
197
198      inline node_pointer
199      fix(node_pointer p_nd) const;
200
201      inline void
202      insert_node(node_pointer p_nd);
203
204      inline void
205      remove_parentless_node(node_pointer p_nd);
206
207      inline node_pointer
208      join(node_pointer p_lhs, node_pointer p_rhs) const;
209
210#ifdef _GLIBCXX_DEBUG
211      void
212      assert_node_consistent(const_node_pointer, bool, bool) const;
213#endif
214
215    protected:
216      node_pointer m_p_max;
217    };
218
219#include <ext/pb_ds/detail/binomial_heap_base_/constructors_destructor_fn_imps.hpp>
220#include <ext/pb_ds/detail/binomial_heap_base_/debug_fn_imps.hpp>
221#include <ext/pb_ds/detail/binomial_heap_base_/find_fn_imps.hpp>
222#include <ext/pb_ds/detail/binomial_heap_base_/insert_fn_imps.hpp>
223#include <ext/pb_ds/detail/binomial_heap_base_/erase_fn_imps.hpp>
224#include <ext/pb_ds/detail/binomial_heap_base_/split_join_fn_imps.hpp>
225
226#undef PB_DS_CLASS_C_DEC
227#undef PB_DS_CLASS_T_DEC
228#undef PB_DS_BASE_C_DEC
229
230
231  } // namespace detail
232} // namespace __gnu_pbds
233
234#endif
235