Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / include / ext / pb_assoc / detail / bin_search_tree_ / debug_fn_imps.hpp
blobf3b12d06d6f9eab2eb646ee2a5214846270340cb
1 // -*- C++ -*-
3 // Copyright (C) 2005 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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
40 /**
41 * @file debug_fn_imps.hpp
42 * Contains an implementation class for bin_search_tree_.
45 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
47 PB_ASSOC_CLASS_T_DEC
48 void
49 PB_ASSOC_CLASS_C_DEC::
50 assert_valid(bool check_iterators, bool check_metadata) const
52 PB_ASSOC_DBG_ASSERT(m_p_head != NULL);
54 if (m_p_head->m_p_parent == NULL)
56 PB_ASSOC_DBG_ASSERT(m_p_head->m_p_left == m_p_head);
57 PB_ASSOC_DBG_ASSERT(m_p_head->m_p_right == m_p_head);
59 if (check_metadata)
60 PB_ASSOC_DBG_ASSERT(m_size == 0);
62 else
64 PB_ASSOC_DBG_ASSERT(m_p_head->m_p_parent->m_p_parent == m_p_head);
66 PB_ASSOC_DBG_ASSERT(m_p_head->m_p_left != m_p_head);
67 PB_ASSOC_DBG_ASSERT(m_p_head->m_p_right != m_p_head);
69 if (check_metadata)
70 PB_ASSOC_DBG_ASSERT(m_size > 0);
73 if (check_metadata)
74 assert_size();
76 if (m_p_head->m_p_parent != NULL)
77 assert_node_consistent(m_p_head->m_p_parent);
79 assert_min();
80 assert_max();
82 if (check_metadata)
83 assert_consistent_with_debug_base();
85 if (check_iterators&& check_metadata)
86 assert_iterators();
89 PB_ASSOC_CLASS_T_DEC
90 void
91 PB_ASSOC_CLASS_C_DEC::
92 assert_node_consistent_with_left(const node_pointer p_nd) const
94 if (p_nd->m_p_left == NULL)
95 return;
97 PB_ASSOC_DBG_ASSERT(p_nd->m_p_left->m_p_parent == p_nd);
99 PB_ASSOC_DBG_ASSERT(!Cmp_Fn::operator()(
100 PB_ASSOC_V2F(p_nd->m_value),
101 PB_ASSOC_V2F(p_nd->m_p_left->m_value)));
104 PB_ASSOC_CLASS_T_DEC
105 void
106 PB_ASSOC_CLASS_C_DEC::
107 assert_node_consistent_with_right(const node_pointer p_nd) const
109 if (p_nd->m_p_right == NULL)
110 return;
112 PB_ASSOC_DBG_ASSERT(p_nd->m_p_right->m_p_parent == p_nd);
114 PB_ASSOC_DBG_ASSERT(!Cmp_Fn::operator()(
115 PB_ASSOC_V2F(p_nd->m_p_right->m_value),
116 PB_ASSOC_V2F(p_nd->m_value)));
119 PB_ASSOC_CLASS_T_DEC
120 void
121 PB_ASSOC_CLASS_C_DEC::
122 assert_min() const
124 assert_min_imp(m_p_head->m_p_parent);
127 PB_ASSOC_CLASS_T_DEC
128 void
129 PB_ASSOC_CLASS_C_DEC::
130 assert_min_imp(const node_pointer p_nd) const
132 if (p_nd == NULL)
134 PB_ASSOC_DBG_ASSERT(m_p_head->m_p_left == m_p_head);
136 return;
139 if (p_nd->m_p_left == NULL)
141 PB_ASSOC_DBG_ASSERT(p_nd == m_p_head->m_p_left);
143 return;
146 assert_min_imp(p_nd->m_p_left);
149 PB_ASSOC_CLASS_T_DEC
150 void
151 PB_ASSOC_CLASS_C_DEC::
152 assert_max() const
154 assert_max_imp(m_p_head->m_p_parent);
157 PB_ASSOC_CLASS_T_DEC
158 void
159 PB_ASSOC_CLASS_C_DEC::
160 assert_max_imp(const node_pointer p_nd) const
162 if (p_nd == NULL)
164 PB_ASSOC_DBG_ASSERT(m_p_head->m_p_right == m_p_head);
166 return;
169 if (p_nd->m_p_right == NULL)
171 PB_ASSOC_DBG_ASSERT(p_nd == m_p_head->m_p_right);
173 return;
176 assert_max_imp(p_nd->m_p_right);
179 PB_ASSOC_CLASS_T_DEC
180 void
181 PB_ASSOC_CLASS_C_DEC::
182 assert_iterators() const
184 PB_ASSOC_DBG_ASSERT(m_end_it.m_p_nd == m_p_head);
185 PB_ASSOC_DBG_ASSERT(m_rend_it.m_p_nd == m_p_head);
187 size_type iterated_num = 0;
189 const_iterator prev_it = end();
191 for (const_iterator it = begin(); it != end(); ++it)
193 ++iterated_num;
195 PB_ASSOC_DBG_ASSERT(lower_bound(
196 PB_ASSOC_V2F(*it)).m_p_nd == it.m_p_nd);
198 const_iterator upper_bound_it = upper_bound(
199 PB_ASSOC_V2F(*it));
201 --upper_bound_it;
203 PB_ASSOC_DBG_ASSERT(upper_bound_it.m_p_nd == it.m_p_nd);
205 if (prev_it != end())
206 PB_ASSOC_DBG_ASSERT(Cmp_Fn::operator()(
207 PB_ASSOC_V2F(*prev_it),
208 PB_ASSOC_V2F(*it)));
210 prev_it = it;
213 PB_ASSOC_DBG_ASSERT(iterated_num == m_size);
215 size_type reverse_iterated_num = 0;
217 const_reverse_iterator reverse_prev_it = rend();
219 for (const_reverse_iterator reverse_it = rbegin(); reverse_it != rend();
220 ++reverse_it)
222 ++reverse_iterated_num;
224 PB_ASSOC_DBG_ASSERT(lower_bound(
225 PB_ASSOC_V2F(*reverse_it)).m_p_nd == reverse_it.m_p_nd);
227 const_iterator upper_bound_it = upper_bound(
228 PB_ASSOC_V2F(*reverse_it));
230 --upper_bound_it;
232 PB_ASSOC_DBG_ASSERT(upper_bound_it.m_p_nd == reverse_it.m_p_nd);
234 if (reverse_prev_it != rend())
235 PB_ASSOC_DBG_ASSERT(!Cmp_Fn::operator()(
236 PB_ASSOC_V2F(*reverse_prev_it),
237 PB_ASSOC_V2F(*reverse_it)));
239 reverse_prev_it = reverse_it;
242 PB_ASSOC_DBG_ASSERT(reverse_iterated_num == m_size);
245 PB_ASSOC_CLASS_T_DEC
246 void
247 PB_ASSOC_CLASS_C_DEC::
248 assert_consistent_with_debug_base() const
250 my_map_debug_base::check_size(m_size);
252 assert_consistent_with_debug_base(m_p_head->m_p_parent);
255 PB_ASSOC_CLASS_T_DEC
256 void
257 PB_ASSOC_CLASS_C_DEC::
258 assert_consistent_with_debug_base(const node_pointer p_nd) const
260 if (p_nd == NULL)
261 return;
263 my_map_debug_base::check_key_exists(
264 PB_ASSOC_V2F(p_nd->m_value));
266 assert_consistent_with_debug_base(p_nd->m_p_left);
267 assert_consistent_with_debug_base(p_nd->m_p_right);
270 PB_ASSOC_CLASS_T_DEC
271 void
272 PB_ASSOC_CLASS_C_DEC::
273 assert_size() const
275 PB_ASSOC_DBG_ASSERT(recursive_count(m_p_head->m_p_parent) == m_size);
278 #endif // #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_