libstdc++
rc_binomial_heap_.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the terms
00007 // of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 3, or (at your option) any later
00009 // version.
00010 
00011 // This library is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00026 
00027 // Permission to use, copy, modify, sell, and distribute this software
00028 // is hereby granted without fee, provided that the above copyright
00029 // notice appears in all copies, and that both that copyright notice
00030 // and this permission notice appear in supporting documentation. None
00031 // of the above authors, nor IBM Haifa Research Laboratories, make any
00032 // representation about the suitability of this software for any
00033 // purpose. It is provided "as is" without express or implied
00034 // warranty.
00035 
00036 /**
00037  * @file rc_binomial_heap_/rc_binomial_heap_.hpp
00038  * Contains an implementation for redundant-counter binomial heap.
00039  */
00040 
00041 #include <ext/pb_ds/detail/cond_dealtor.hpp>
00042 #include <ext/pb_ds/detail/type_utils.hpp>
00043 #include <ext/pb_ds/detail/binomial_heap_base_/binomial_heap_base_.hpp>
00044 #include <ext/pb_ds/detail/rc_binomial_heap_/rc.hpp>
00045 #include <debug/debug.h>
00046 
00047 namespace __gnu_pbds
00048 {
00049   namespace detail
00050   {
00051 #define PB_DS_CLASS_T_DEC \
00052     template<typename Value_Type, typename Cmp_Fn, typename _Alloc>
00053 
00054 #define PB_DS_CLASS_C_DEC \
00055     rc_binomial_heap<Value_Type, Cmp_Fn, _Alloc>
00056 
00057 #define PB_DS_RC_C_DEC \
00058     rc<typename binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>::node, _Alloc>
00059 
00060     /**
00061      *  Redundant-counter binomial heap.
00062      *
00063      *  @ingroup heap-detail
00064      */
00065     template<typename Value_Type, typename Cmp_Fn, typename _Alloc>
00066     class rc_binomial_heap
00067     : public binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>
00068     {
00069     private:
00070       typedef binomial_heap_base<Value_Type, Cmp_Fn, _Alloc>
00071                                 base_type;
00072       typedef typename base_type::node_pointer      node_pointer;
00073       typedef typename base_type::node_const_pointer    node_const_pointer;
00074       typedef PB_DS_RC_C_DEC                rc_t;
00075 
00076     public:
00077       typedef Value_Type                value_type;
00078       typedef typename _Alloc::size_type        size_type;
00079       typedef typename _Alloc::difference_type      difference_type;
00080       typedef typename base_type::pointer       pointer;
00081       typedef typename base_type::const_pointer     const_pointer;
00082       typedef typename base_type::reference         reference;
00083       typedef typename base_type::const_reference   const_reference;
00084       typedef typename base_type::point_const_iterator  point_const_iterator;
00085       typedef typename base_type::point_iterator    point_iterator;
00086       typedef typename base_type::const_iterator    const_iterator;
00087       typedef typename base_type::iterator      iterator;
00088       typedef typename base_type::cmp_fn        cmp_fn;
00089       typedef typename base_type::allocator_type    allocator_type;
00090 
00091       rc_binomial_heap();
00092 
00093       rc_binomial_heap(const Cmp_Fn&);
00094 
00095       rc_binomial_heap(const PB_DS_CLASS_C_DEC&);
00096 
00097       ~rc_binomial_heap();
00098 
00099       void
00100       swap(PB_DS_CLASS_C_DEC&);
00101 
00102       inline point_iterator
00103       push(const_reference);
00104 
00105       void
00106       modify(point_iterator, const_reference);
00107 
00108       inline void
00109       pop();
00110 
00111       void
00112       erase(point_iterator);
00113 
00114       inline void
00115       clear();
00116 
00117       template<typename Pred>
00118       size_type
00119       erase_if(Pred);
00120 
00121       template<typename Pred>
00122       void
00123       split(Pred, PB_DS_CLASS_C_DEC&);
00124 
00125       void
00126       join(PB_DS_CLASS_C_DEC&);
00127 
00128 #ifdef _GLIBCXX_DEBUG
00129       void
00130       assert_valid(const char*, int) const;
00131 #endif
00132 
00133 #ifdef PB_DS_RC_BINOMIAL_HEAP_TRACE_
00134       void
00135       trace() const;
00136 #endif
00137 
00138     private:
00139 
00140       inline node_pointer
00141       link_with_next_sibling(node_pointer);
00142 
00143       void
00144       make_0_exposed();
00145 
00146       void
00147       make_binomial_heap();
00148 
00149 #ifdef _GLIBCXX_DEBUG
00150       static node_const_pointer
00151       next_2_pointer(node_const_pointer);
00152 
00153       static node_const_pointer
00154       next_after_0_pointer(node_const_pointer);
00155 #endif
00156 
00157       rc_t          m_rc;
00158     };
00159 
00160 #include <ext/pb_ds/detail/rc_binomial_heap_/constructors_destructor_fn_imps.hpp>
00161 #include <ext/pb_ds/detail/rc_binomial_heap_/debug_fn_imps.hpp>
00162 #include <ext/pb_ds/detail/rc_binomial_heap_/erase_fn_imps.hpp>
00163 #include <ext/pb_ds/detail/rc_binomial_heap_/trace_fn_imps.hpp>
00164 #include <ext/pb_ds/detail/rc_binomial_heap_/insert_fn_imps.hpp>
00165 #include <ext/pb_ds/detail/rc_binomial_heap_/split_join_fn_imps.hpp>
00166 
00167 #undef PB_DS_CLASS_C_DEC
00168 #undef PB_DS_CLASS_T_DEC
00169 #undef PB_DS_RC_C_DEC
00170   } // namespace detail
00171 } // namespace __gnu_pbds