]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.1.0/include/ext/pb_assoc/detail/bin_search_tree_/debug_fn_imps.hpp
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.1.0 / include / ext / pb_assoc / detail / bin_search_tree_ / debug_fn_imps.hpp
1 // -*- C++ -*-
2
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.
10
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.
15
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.
20
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.
29
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
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.
39
40 /**
41  * @file debug_fn_imps.hpp
42  * Contains an implementation class for bin_search_tree_.
43  */
44
45 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
46
47 PB_ASSOC_CLASS_T_DEC
48 void
49 PB_ASSOC_CLASS_C_DEC::
50 assert_valid(bool check_iterators, bool check_metadata) const
51 {
52   PB_ASSOC_DBG_ASSERT(m_p_head != NULL);
53
54   if (m_p_head->m_p_parent == NULL)
55     {
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);
58
59       if (check_metadata)
60         PB_ASSOC_DBG_ASSERT(m_size == 0);
61     }
62   else
63     {
64       PB_ASSOC_DBG_ASSERT(m_p_head->m_p_parent->m_p_parent == m_p_head);
65
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);
68
69       if (check_metadata)
70         PB_ASSOC_DBG_ASSERT(m_size > 0);
71     }
72
73   if (check_metadata)
74     assert_size();
75
76   if (m_p_head->m_p_parent != NULL)
77     assert_node_consistent(m_p_head->m_p_parent);
78
79   assert_min();
80   assert_max();
81
82   if (check_metadata)
83     assert_consistent_with_debug_base();
84
85   if (check_iterators&&  check_metadata)
86     assert_iterators();
87 }
88
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
93 {
94   if (p_nd->m_p_left == NULL)
95     return;
96
97   PB_ASSOC_DBG_ASSERT(p_nd->m_p_left->m_p_parent == p_nd);
98
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)));
102 }
103
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
108 {
109   if (p_nd->m_p_right == NULL)
110     return;
111
112   PB_ASSOC_DBG_ASSERT(p_nd->m_p_right->m_p_parent == p_nd);
113
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)));
117 }
118
119 PB_ASSOC_CLASS_T_DEC
120 void
121 PB_ASSOC_CLASS_C_DEC::
122 assert_min() const
123 {
124   assert_min_imp(m_p_head->m_p_parent);
125 }
126
127 PB_ASSOC_CLASS_T_DEC
128 void
129 PB_ASSOC_CLASS_C_DEC::
130 assert_min_imp(const node_pointer p_nd) const
131 {
132   if (p_nd == NULL)
133     {
134       PB_ASSOC_DBG_ASSERT(m_p_head->m_p_left == m_p_head);
135
136       return;
137     }
138
139   if (p_nd->m_p_left == NULL)
140     {
141       PB_ASSOC_DBG_ASSERT(p_nd == m_p_head->m_p_left);
142
143       return;
144     }
145
146   assert_min_imp(p_nd->m_p_left);
147 }
148
149 PB_ASSOC_CLASS_T_DEC
150 void
151 PB_ASSOC_CLASS_C_DEC::
152 assert_max() const
153 {
154   assert_max_imp(m_p_head->m_p_parent);
155 }
156
157 PB_ASSOC_CLASS_T_DEC
158 void
159 PB_ASSOC_CLASS_C_DEC::
160 assert_max_imp(const node_pointer p_nd) const
161 {
162   if (p_nd == NULL)
163     {
164       PB_ASSOC_DBG_ASSERT(m_p_head->m_p_right == m_p_head);
165
166       return;
167     }
168
169   if (p_nd->m_p_right == NULL)
170     {
171       PB_ASSOC_DBG_ASSERT(p_nd == m_p_head->m_p_right);
172
173       return;
174     }
175
176   assert_max_imp(p_nd->m_p_right);
177 }
178
179 PB_ASSOC_CLASS_T_DEC
180 void
181 PB_ASSOC_CLASS_C_DEC::
182 assert_iterators() const
183 {
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);
186
187   size_type iterated_num = 0;
188
189   const_iterator prev_it = end();
190
191   for (const_iterator it = begin(); it != end(); ++it)
192     {
193       ++iterated_num;
194
195       PB_ASSOC_DBG_ASSERT(lower_bound(
196                                       PB_ASSOC_V2F(*it)).m_p_nd == it.m_p_nd);
197
198       const_iterator upper_bound_it = upper_bound(
199                                                   PB_ASSOC_V2F(*it));
200
201       --upper_bound_it;
202
203       PB_ASSOC_DBG_ASSERT(upper_bound_it.m_p_nd == it.m_p_nd);
204
205       if (prev_it != end())
206         PB_ASSOC_DBG_ASSERT(Cmp_Fn::operator()(
207                                                PB_ASSOC_V2F(*prev_it),
208                                                PB_ASSOC_V2F(*it)));
209
210       prev_it = it;
211     }
212
213   PB_ASSOC_DBG_ASSERT(iterated_num == m_size);
214
215   size_type reverse_iterated_num = 0;
216
217   const_reverse_iterator reverse_prev_it = rend();
218
219   for (const_reverse_iterator reverse_it = rbegin(); reverse_it != rend();
220        ++reverse_it)
221     {
222       ++reverse_iterated_num;
223
224       PB_ASSOC_DBG_ASSERT(lower_bound(
225                                       PB_ASSOC_V2F(*reverse_it)).m_p_nd == reverse_it.m_p_nd);
226
227       const_iterator upper_bound_it = upper_bound(
228                                                   PB_ASSOC_V2F(*reverse_it));
229
230       --upper_bound_it;
231
232       PB_ASSOC_DBG_ASSERT(upper_bound_it.m_p_nd == reverse_it.m_p_nd);
233
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)));
238
239       reverse_prev_it = reverse_it;
240     }
241
242   PB_ASSOC_DBG_ASSERT(reverse_iterated_num == m_size);
243 }
244
245 PB_ASSOC_CLASS_T_DEC
246 void
247 PB_ASSOC_CLASS_C_DEC::
248 assert_consistent_with_debug_base() const
249 {
250   my_map_debug_base::check_size(m_size);
251
252   assert_consistent_with_debug_base(m_p_head->m_p_parent);
253 }
254
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
259 {
260   if (p_nd == NULL)
261     return;
262
263   my_map_debug_base::check_key_exists(
264                                       PB_ASSOC_V2F(p_nd->m_value));
265
266   assert_consistent_with_debug_base(p_nd->m_p_left);
267   assert_consistent_with_debug_base(p_nd->m_p_right);
268 }
269
270 PB_ASSOC_CLASS_T_DEC
271 void
272 PB_ASSOC_CLASS_C_DEC::
273 assert_size() const
274 {
275   PB_ASSOC_DBG_ASSERT(recursive_count(m_p_head->m_p_parent) == m_size);
276 }
277
278 #endif // #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_