3 // Copyright (C) 2005, 2006 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 2, 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 // 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
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
43 * @file debug_fn_imps.hpp
44 * Contains an implementation class for bin_search_tree_.
54 structure_only_assert_valid();
55 assert_consistent_with_debug_base();
58 if (m_p_head
->m_p_parent
== NULL
)
60 _GLIBCXX_DEBUG_ASSERT(m_size
== 0);
64 _GLIBCXX_DEBUG_ASSERT(m_size
> 0);
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
);
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
);
95 assert_node_consistent(const node_pointer p_nd
) const
97 assert_node_consistent_(p_nd
);
101 typename
PB_DS_CLASS_C_DEC::node_consistent_t
103 assert_node_consistent_(const node_pointer p_nd
) const
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
));
131 assert_node_consistent_with_left(const node_pointer p_nd
) const
133 if (p_nd
->m_p_left
== NULL
)
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
)));
143 assert_node_consistent_with_right(const node_pointer p_nd
) const
145 if (p_nd
->m_p_right
== NULL
)
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
)));
157 assert_min_imp(m_p_head
->m_p_parent
);
163 assert_min_imp(const node_pointer p_nd
) const
167 _GLIBCXX_DEBUG_ASSERT(m_p_head
->m_p_left
== m_p_head
);
171 if (p_nd
->m_p_left
== NULL
)
173 _GLIBCXX_DEBUG_ASSERT(p_nd
== m_p_head
->m_p_left
);
176 assert_min_imp(p_nd
->m_p_left
);
184 assert_max_imp(m_p_head
->m_p_parent
);
190 assert_max_imp(const node_pointer p_nd
) const
194 _GLIBCXX_DEBUG_ASSERT(m_p_head
->m_p_right
== m_p_head
);
198 if (p_nd
->m_p_right
== NULL
)
200 _GLIBCXX_DEBUG_ASSERT(p_nd
== m_p_head
->m_p_right
);
204 assert_max_imp(p_nd
->m_p_right
);
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
)
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
));
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
),
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();
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
));
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
);
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
);
261 assert_consistent_with_debug_base(const node_pointer p_nd
) const
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
);
275 _GLIBCXX_DEBUG_ASSERT(recursive_count(m_p_head
->m_p_parent
) == m_size
);