libstdc++
rc_binomial_heap_/debug_fn_imps.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2009, 2010, 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_/debug_fn_imps.hpp
00038  * Contains an implementation for rc_binomial_heap_.
00039  */
00040 
00041 #ifdef _GLIBCXX_DEBUG
00042 
00043 PB_DS_CLASS_T_DEC
00044 void
00045 PB_DS_CLASS_C_DEC::
00046 assert_valid(const char* __file, int __line) const
00047 {
00048   base_type::assert_valid(false, __file, __line);
00049   if (!base_type::empty())
00050     {
00051       PB_DS_DEBUG_VERIFY(base_type::m_p_max != 0);
00052       base_type::assert_max(__file, __line);
00053     }
00054 
00055   m_rc.assert_valid(__file, __line);
00056 
00057   if (m_rc.empty())
00058     {
00059       base_type::assert_valid(true, __file, __line);
00060       PB_DS_DEBUG_VERIFY(next_2_pointer(base_type::m_p_root) == 0);
00061       return;
00062     }
00063 
00064   node_const_pointer p_nd = next_2_pointer(base_type::m_p_root);
00065   typename rc_t::const_iterator it = m_rc.end();
00066   --it;
00067 
00068   while (p_nd != 0)
00069     {
00070       PB_DS_DEBUG_VERIFY(*it == p_nd);
00071       node_const_pointer p_next = p_nd->m_p_next_sibling;
00072       PB_DS_DEBUG_VERIFY(p_next != 0);
00073       PB_DS_DEBUG_VERIFY(p_nd->m_metadata == p_next->m_metadata);
00074       PB_DS_DEBUG_VERIFY(p_next->m_p_next_sibling == 0 ||
00075                p_next->m_metadata < p_next->m_p_next_sibling->m_metadata);
00076 
00077       --it;
00078       p_nd = next_2_pointer(next_after_0_pointer(p_nd));
00079     }
00080   PB_DS_DEBUG_VERIFY(it + 1 == m_rc.begin());
00081 }
00082 
00083 PB_DS_CLASS_T_DEC
00084 typename PB_DS_CLASS_C_DEC::node_const_pointer
00085 PB_DS_CLASS_C_DEC::
00086 next_2_pointer(node_const_pointer p_nd)
00087 {
00088   if (p_nd == 0)
00089     return 0;
00090 
00091   node_pointer p_next = p_nd->m_p_next_sibling;
00092 
00093   if (p_next == 0)
00094     return 0;
00095 
00096   if (p_nd->m_metadata == p_next->m_metadata)
00097     return p_nd;
00098 
00099   return next_2_pointer(p_next);
00100 }
00101 
00102 PB_DS_CLASS_T_DEC
00103 typename PB_DS_CLASS_C_DEC::node_const_pointer
00104 PB_DS_CLASS_C_DEC::
00105 next_after_0_pointer(node_const_pointer p_nd)
00106 {
00107   if (p_nd == 0)
00108     return 0;
00109 
00110   node_pointer p_next = p_nd->m_p_next_sibling;
00111 
00112   if (p_next == 0)
00113     return 0;
00114 
00115   if (p_nd->m_metadata < p_next->m_metadata)
00116     return p_next;
00117 
00118   return next_after_0_pointer(p_next);
00119 }
00120 
00121 #endif