3 // Copyright (C) 2005-2024 Free Software Foundation, Inc.
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
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.
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.
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/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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
37 * @file bin_search_tree_/debug_fn_imps.hpp
38 * Contains an implementation class for bin_search_tree_.
41 #ifdef PB_DS_CLASS_C_DEC
48 assert_valid(const char* __file, int __line) const
50 structure_only_assert_valid(__file, __line);
51 assert_consistent_with_debug_base(__file, __line);
52 assert_size(__file, __line);
53 assert_iterators(__file, __line);
54 if (m_p_head->m_p_parent == 0)
56 PB_DS_DEBUG_VERIFY(m_size == 0);
60 PB_DS_DEBUG_VERIFY(m_size > 0);
67 structure_only_assert_valid(const char* __file, int __line) const
69 PB_DS_DEBUG_VERIFY(m_p_head != 0);
70 if (m_p_head->m_p_parent == 0)
72 PB_DS_DEBUG_VERIFY(m_p_head->m_p_left == m_p_head);
73 PB_DS_DEBUG_VERIFY(m_p_head->m_p_right == m_p_head);
77 PB_DS_DEBUG_VERIFY(m_p_head->m_p_parent->m_p_parent == m_p_head);
78 PB_DS_DEBUG_VERIFY(m_p_head->m_p_left != m_p_head);
79 PB_DS_DEBUG_VERIFY(m_p_head->m_p_right != m_p_head);
82 if (m_p_head->m_p_parent != 0)
83 assert_node_consistent(m_p_head->m_p_parent, __file, __line);
84 assert_min(__file, __line);
85 assert_max(__file, __line);
91 assert_node_consistent(const node_pointer p_nd,
92 const char* __file, int __line) const
94 assert_node_consistent_(p_nd, __file, __line);
98 typename PB_DS_CLASS_C_DEC::node_consistent_t
100 assert_node_consistent_(const node_pointer p_nd,
101 const char* __file, int __line) const
104 return (std::make_pair((const_pointer)0,(const_pointer)0));
106 assert_node_consistent_with_left(p_nd, __file, __line);
107 assert_node_consistent_with_right(p_nd, __file, __line);
109 const std::pair<const_pointer, const_pointer>
110 l_range = assert_node_consistent_(p_nd->m_p_left, __file, __line);
112 if (l_range.second != 0)
113 PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(*l_range.second),
114 PB_DS_V2F(p_nd->m_value)));
116 const std::pair<const_pointer, const_pointer>
117 r_range = assert_node_consistent_(p_nd->m_p_right, __file, __line);
119 if (r_range.first != 0)
120 PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value),
121 PB_DS_V2F(*r_range.first)));
123 return std::make_pair((l_range.first != 0) ? l_range.first : &p_nd->m_value,
124 (r_range.second != 0)? r_range.second : &p_nd->m_value);
130 assert_node_consistent_with_left(const node_pointer p_nd,
131 const char* __file, int __line) const
133 if (p_nd->m_p_left == 0)
135 PB_DS_DEBUG_VERIFY(p_nd->m_p_left->m_p_parent == p_nd);
136 PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value),
137 PB_DS_V2F(p_nd->m_p_left->m_value)));
143 assert_node_consistent_with_right(const node_pointer p_nd,
144 const char* __file, int __line) const
146 if (p_nd->m_p_right == 0)
148 PB_DS_DEBUG_VERIFY(p_nd->m_p_right->m_p_parent == p_nd);
149 PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_p_right->m_value),
150 PB_DS_V2F(p_nd->m_value)));
156 assert_min(const char* __file, int __line) const
158 assert_min_imp(m_p_head->m_p_parent, __file, __line);
164 assert_min_imp(const node_pointer p_nd, const char* __file, int __line) const
168 PB_DS_DEBUG_VERIFY(m_p_head->m_p_left == m_p_head);
172 if (p_nd->m_p_left == 0)
174 PB_DS_DEBUG_VERIFY(p_nd == m_p_head->m_p_left);
177 assert_min_imp(p_nd->m_p_left, __file, __line);
183 assert_max(const char* __file, int __line) const
185 assert_max_imp(m_p_head->m_p_parent, __file, __line);
191 assert_max_imp(const node_pointer p_nd,
192 const char* __file, int __line) const
196 PB_DS_DEBUG_VERIFY(m_p_head->m_p_right == m_p_head);
200 if (p_nd->m_p_right == 0)
202 PB_DS_DEBUG_VERIFY(p_nd == m_p_head->m_p_right);
206 assert_max_imp(p_nd->m_p_right, __file, __line);
212 assert_iterators(const char* __file, int __line) const
214 size_type iterated_num = 0;
215 const_iterator prev_it = end();
216 for (const_iterator it = begin(); it != end(); ++it)
219 PB_DS_DEBUG_VERIFY(lower_bound(PB_DS_V2F(*it)).m_p_nd == it.m_p_nd);
220 const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*it));
222 PB_DS_DEBUG_VERIFY(upper_bound_it.m_p_nd == it.m_p_nd);
224 if (prev_it != end())
225 PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(*prev_it),
230 PB_DS_DEBUG_VERIFY(iterated_num == m_size);
231 size_type reverse_iterated_num = 0;
232 const_reverse_iterator reverse_prev_it = rend();
233 for (const_reverse_iterator reverse_it = rbegin(); reverse_it != rend();
236 ++reverse_iterated_num;
237 PB_DS_DEBUG_VERIFY(lower_bound(
238 PB_DS_V2F(*reverse_it)).m_p_nd == reverse_it.m_p_nd);
240 const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*reverse_it));
242 PB_DS_DEBUG_VERIFY(upper_bound_it.m_p_nd == reverse_it.m_p_nd);
243 if (reverse_prev_it != rend())
244 PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(PB_DS_V2F(*reverse_prev_it),
245 PB_DS_V2F(*reverse_it)));
246 reverse_prev_it = reverse_it;
248 PB_DS_DEBUG_VERIFY(reverse_iterated_num == m_size);
254 assert_consistent_with_debug_base(const char* __file, int __line) const
256 debug_base::check_size(m_size, __file, __line);
257 assert_consistent_with_debug_base(m_p_head->m_p_parent, __file, __line);
263 assert_consistent_with_debug_base(const node_pointer p_nd,
264 const char* __file, int __line) const
268 debug_base::check_key_exists(PB_DS_V2F(p_nd->m_value), __file, __line);
269 assert_consistent_with_debug_base(p_nd->m_p_left, __file, __line);
270 assert_consistent_with_debug_base(p_nd->m_p_right, __file, __line);
276 assert_size(const char* __file, int __line) const
277 { PB_DS_DEBUG_VERIFY(recursive_count(m_p_head->m_p_parent) == m_size); }