libstdc++
|
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 left_child_next_sibling_heap_/debug_fn_imps.hpp 00038 * Contains an implementation class for left_child_next_sibling_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 PB_DS_DEBUG_VERIFY(m_p_root == 0 || m_p_root->m_p_prev_or_parent == 0); 00049 00050 if (m_p_root != 0) 00051 assert_node_consistent(m_p_root, Single_Link_Roots, __file, __line); 00052 assert_size(__file, __line); 00053 assert_iterators(__file, __line); 00054 } 00055 00056 PB_DS_CLASS_T_DEC 00057 void 00058 PB_DS_CLASS_C_DEC:: 00059 assert_node_consistent(node_const_pointer p_nd, bool single_link, 00060 const char* __file, int __line) const 00061 { 00062 if (p_nd == 0) 00063 return; 00064 00065 assert_node_consistent(p_nd->m_p_l_child, false, __file, __line); 00066 assert_node_consistent(p_nd->m_p_next_sibling, single_link, __file, __line); 00067 00068 if (single_link) 00069 PB_DS_DEBUG_VERIFY(p_nd->m_p_prev_or_parent == 0); 00070 else if (p_nd->m_p_next_sibling != 0) 00071 PB_DS_DEBUG_VERIFY(p_nd->m_p_next_sibling->m_p_prev_or_parent == p_nd); 00072 00073 if (p_nd->m_p_l_child == 0) 00074 return; 00075 00076 node_const_pointer p_child = p_nd->m_p_l_child; 00077 while (p_child != 0) 00078 { 00079 node_const_pointer p_next_child = p_child->m_p_next_sibling; 00080 PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(p_nd->m_value, p_child->m_value)); 00081 p_child = p_next_child; 00082 } 00083 PB_DS_DEBUG_VERIFY(p_nd->m_p_l_child->m_p_prev_or_parent == p_nd); 00084 } 00085 00086 PB_DS_CLASS_T_DEC 00087 void 00088 PB_DS_CLASS_C_DEC:: 00089 assert_iterators(const char* __file, int __line) const 00090 { 00091 PB_DS_DEBUG_VERIFY(std::distance(begin(), end()) == size()); 00092 } 00093 00094 PB_DS_CLASS_T_DEC 00095 void 00096 PB_DS_CLASS_C_DEC:: 00097 assert_size(const char* __file, int __line) const 00098 { 00099 PB_DS_DEBUG_VERIFY(size_from_node(m_p_root) == m_size); 00100 } 00101 00102 PB_DS_CLASS_T_DEC 00103 typename PB_DS_CLASS_C_DEC::size_type 00104 PB_DS_CLASS_C_DEC:: 00105 size_under_node(node_const_pointer p_nd) 00106 { return 1 + size_from_node(p_nd->m_p_l_child); } 00107 00108 PB_DS_CLASS_T_DEC 00109 typename PB_DS_CLASS_C_DEC::size_type 00110 PB_DS_CLASS_C_DEC:: 00111 size_from_node(node_const_pointer p_nd) 00112 { 00113 size_type ret = 0; 00114 while (p_nd != 0) 00115 { 00116 ret += 1 + size_from_node(p_nd->m_p_l_child); 00117 p_nd = p_nd->m_p_next_sibling; 00118 } 00119 return ret; 00120 } 00121 00122 PB_DS_CLASS_T_DEC 00123 typename PB_DS_CLASS_C_DEC::size_type 00124 PB_DS_CLASS_C_DEC:: 00125 degree(node_const_pointer p_nd) 00126 { 00127 size_type ret = 0; 00128 node_const_pointer p_child = p_nd->m_p_l_child; 00129 while (p_child != 0) 00130 { 00131 ++ret; 00132 p_child = p_child->m_p_next_sibling; 00133 } 00134 return ret; 00135 } 00136 00137 #endif