Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / pb_ds / detail / bin_search_tree_ / debug_fn_imps.hpp
blobd0a0752dee0b6e386f7e10f9c9a86d9523757f1a
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
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 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
42 /**
43 * @file debug_fn_imps.hpp
44 * Contains an implementation class for bin_search_tree_.
47 #ifdef _GLIBCXX_DEBUG
49 PB_DS_CLASS_T_DEC
50 void
51 PB_DS_CLASS_C_DEC::
52 assert_valid() const
54 structure_only_assert_valid();
55 assert_consistent_with_debug_base();
56 assert_size();
57 assert_iterators();
58 if (m_p_head->m_p_parent == NULL)
60 _GLIBCXX_DEBUG_ASSERT(m_size == 0);
62 else
64 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
68 PB_DS_CLASS_T_DEC
69 void
70 PB_DS_CLASS_C_DEC::
71 structure_only_assert_valid() const
73 _GLIBCXX_DEBUG_ASSERT(m_p_head != NULL);
74 if (m_p_head->m_p_parent == NULL)
76 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_left == m_p_head);
77 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_right == m_p_head);
79 else
81 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_parent->m_p_parent == m_p_head);
82 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_left != m_p_head);
83 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_right != m_p_head);
86 if (m_p_head->m_p_parent != NULL)
87 assert_node_consistent(m_p_head->m_p_parent);
88 assert_min();
89 assert_max();
92 PB_DS_CLASS_T_DEC
93 void
94 PB_DS_CLASS_C_DEC::
95 assert_node_consistent(const node_pointer p_nd) const
97 assert_node_consistent_(p_nd);
100 PB_DS_CLASS_T_DEC
101 typename PB_DS_CLASS_C_DEC::node_consistent_t
102 PB_DS_CLASS_C_DEC::
103 assert_node_consistent_(const node_pointer p_nd) const
105 if (p_nd == NULL)
106 return (std::make_pair((const_pointer)NULL,(const_pointer)NULL));
108 assert_node_consistent_with_left(p_nd);
109 assert_node_consistent_with_right(p_nd);
111 const std::pair<const_pointer, const_pointer>
112 l_range = assert_node_consistent_(p_nd->m_p_left);
114 if (l_range.second != NULL)
115 _GLIBCXX_DEBUG_ASSERT(Cmp_Fn::operator()(PB_DS_V2F(*l_range.second),
116 PB_DS_V2F(p_nd->m_value)));
118 const std::pair<const_pointer, const_pointer>
119 r_range = assert_node_consistent_(p_nd->m_p_right);
121 if (r_range.first != NULL)
122 _GLIBCXX_DEBUG_ASSERT(Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value),
123 PB_DS_V2F(*r_range.first)));
125 return (std::make_pair((l_range.first != NULL)? l_range.first :& p_nd->m_value,(r_range.second != NULL)? r_range.second :& p_nd->m_value));
128 PB_DS_CLASS_T_DEC
129 void
130 PB_DS_CLASS_C_DEC::
131 assert_node_consistent_with_left(const node_pointer p_nd) const
133 if (p_nd->m_p_left == NULL)
134 return;
135 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_left->m_p_parent == p_nd);
136 _GLIBCXX_DEBUG_ASSERT(!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value),
137 PB_DS_V2F(p_nd->m_p_left->m_value)));
140 PB_DS_CLASS_T_DEC
141 void
142 PB_DS_CLASS_C_DEC::
143 assert_node_consistent_with_right(const node_pointer p_nd) const
145 if (p_nd->m_p_right == NULL)
146 return;
147 _GLIBCXX_DEBUG_ASSERT(p_nd->m_p_right->m_p_parent == p_nd);
148 _GLIBCXX_DEBUG_ASSERT(!Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_p_right->m_value),
149 PB_DS_V2F(p_nd->m_value)));
152 PB_DS_CLASS_T_DEC
153 void
154 PB_DS_CLASS_C_DEC::
155 assert_min() const
157 assert_min_imp(m_p_head->m_p_parent);
160 PB_DS_CLASS_T_DEC
161 void
162 PB_DS_CLASS_C_DEC::
163 assert_min_imp(const node_pointer p_nd) const
165 if (p_nd == NULL)
167 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_left == m_p_head);
168 return;
171 if (p_nd->m_p_left == NULL)
173 _GLIBCXX_DEBUG_ASSERT(p_nd == m_p_head->m_p_left);
174 return;
176 assert_min_imp(p_nd->m_p_left);
179 PB_DS_CLASS_T_DEC
180 void
181 PB_DS_CLASS_C_DEC::
182 assert_max() const
184 assert_max_imp(m_p_head->m_p_parent);
187 PB_DS_CLASS_T_DEC
188 void
189 PB_DS_CLASS_C_DEC::
190 assert_max_imp(const node_pointer p_nd) const
192 if (p_nd == NULL)
194 _GLIBCXX_DEBUG_ASSERT(m_p_head->m_p_right == m_p_head);
195 return;
198 if (p_nd->m_p_right == NULL)
200 _GLIBCXX_DEBUG_ASSERT(p_nd == m_p_head->m_p_right);
201 return;
204 assert_max_imp(p_nd->m_p_right);
207 PB_DS_CLASS_T_DEC
208 void
209 PB_DS_CLASS_C_DEC::
210 assert_iterators() const
212 size_type iterated_num = 0;
213 const_iterator prev_it = end();
214 for (const_iterator it = begin(); it != end(); ++it)
216 ++iterated_num;
217 _GLIBCXX_DEBUG_ASSERT(lower_bound(PB_DS_V2F(*it)).m_p_nd == it.m_p_nd);
218 const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*it));
219 --upper_bound_it;
220 _GLIBCXX_DEBUG_ASSERT(upper_bound_it.m_p_nd == it.m_p_nd);
222 if (prev_it != end())
223 _GLIBCXX_DEBUG_ASSERT(Cmp_Fn::operator()(PB_DS_V2F(*prev_it),
224 PB_DS_V2F(*it)));
225 prev_it = it;
228 _GLIBCXX_DEBUG_ASSERT(iterated_num == m_size);
229 size_type reverse_iterated_num = 0;
230 const_reverse_iterator reverse_prev_it = rend();
231 for (const_reverse_iterator reverse_it = rbegin(); reverse_it != rend();
232 ++reverse_it)
234 ++reverse_iterated_num;
235 _GLIBCXX_DEBUG_ASSERT(lower_bound(
236 PB_DS_V2F(*reverse_it)).m_p_nd == reverse_it.m_p_nd);
238 const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*reverse_it));
239 --upper_bound_it;
240 _GLIBCXX_DEBUG_ASSERT(upper_bound_it.m_p_nd == reverse_it.m_p_nd);
241 if (reverse_prev_it != rend())
242 _GLIBCXX_DEBUG_ASSERT(!Cmp_Fn::operator()(PB_DS_V2F(*reverse_prev_it),
243 PB_DS_V2F(*reverse_it)));
244 reverse_prev_it = reverse_it;
246 _GLIBCXX_DEBUG_ASSERT(reverse_iterated_num == m_size);
249 PB_DS_CLASS_T_DEC
250 void
251 PB_DS_CLASS_C_DEC::
252 assert_consistent_with_debug_base() const
254 debug_base::check_size(m_size);
255 assert_consistent_with_debug_base(m_p_head->m_p_parent);
258 PB_DS_CLASS_T_DEC
259 void
260 PB_DS_CLASS_C_DEC::
261 assert_consistent_with_debug_base(const node_pointer p_nd) const
263 if (p_nd == NULL)
264 return;
265 debug_base::check_key_exists(PB_DS_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_DS_CLASS_T_DEC
271 void
272 PB_DS_CLASS_C_DEC::
273 assert_size() const
275 _GLIBCXX_DEBUG_ASSERT(recursive_count(m_p_head->m_p_parent) == m_size);
278 #endif