]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/bin_search_tree_/debug_fn_imps.hpp
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / bin_search_tree_ / debug_fn_imps.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
99dee823 3// Copyright (C) 2005-2021 Free Software Foundation, Inc.
4569a895
AT
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
748086b7 8// Foundation; either version 3, or (at your option) any later
4569a895
AT
9// version.
10
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.
15
748086b7
JJ
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.
4569a895 19
748086b7
JJ
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/>.
4569a895
AT
24
25// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
26
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
34// warranty.
35
36/**
a345e45d 37 * @file bin_search_tree_/debug_fn_imps.hpp
4569a895
AT
38 * Contains an implementation class for bin_search_tree_.
39 */
40
574dfb67
JW
41#ifdef PB_DS_CLASS_C_DEC
42
47bea7b8 43#ifdef _GLIBCXX_DEBUG
4569a895
AT
44
45PB_DS_CLASS_T_DEC
46void
47PB_DS_CLASS_C_DEC::
f5886803 48assert_valid(const char* __file, int __line) const
4569a895 49{
f5886803
FD
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);
8fc81078 54 if (m_p_head->m_p_parent == 0)
4569a895 55 {
f5886803 56 PB_DS_DEBUG_VERIFY(m_size == 0);
4569a895
AT
57 }
58 else
59 {
f5886803 60 PB_DS_DEBUG_VERIFY(m_size > 0);
4569a895
AT
61 }
62}
63
64PB_DS_CLASS_T_DEC
65void
66PB_DS_CLASS_C_DEC::
f5886803 67structure_only_assert_valid(const char* __file, int __line) const
4569a895 68{
f5886803 69 PB_DS_DEBUG_VERIFY(m_p_head != 0);
8fc81078 70 if (m_p_head->m_p_parent == 0)
4569a895 71 {
f5886803
FD
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);
4569a895
AT
74 }
75 else
76 {
f5886803
FD
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);
4569a895
AT
80 }
81
8fc81078 82 if (m_p_head->m_p_parent != 0)
f5886803
FD
83 assert_node_consistent(m_p_head->m_p_parent, __file, __line);
84 assert_min(__file, __line);
85 assert_max(__file, __line);
4569a895
AT
86}
87
88PB_DS_CLASS_T_DEC
89void
90PB_DS_CLASS_C_DEC::
f5886803
FD
91assert_node_consistent(const node_pointer p_nd,
92 const char* __file, int __line) const
4569a895 93{
f5886803 94 assert_node_consistent_(p_nd, __file, __line);
4569a895
AT
95}
96
97PB_DS_CLASS_T_DEC
98typename PB_DS_CLASS_C_DEC::node_consistent_t
99PB_DS_CLASS_C_DEC::
f5886803
FD
100assert_node_consistent_(const node_pointer p_nd,
101 const char* __file, int __line) const
4569a895 102{
8fc81078
PC
103 if (p_nd == 0)
104 return (std::make_pair((const_pointer)0,(const_pointer)0));
4569a895 105
f5886803
FD
106 assert_node_consistent_with_left(p_nd, __file, __line);
107 assert_node_consistent_with_right(p_nd, __file, __line);
4569a895
AT
108
109 const std::pair<const_pointer, const_pointer>
f5886803 110 l_range = assert_node_consistent_(p_nd->m_p_left, __file, __line);
4569a895 111
8fc81078 112 if (l_range.second != 0)
f5886803
FD
113 PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(*l_range.second),
114 PB_DS_V2F(p_nd->m_value)));
4569a895
AT
115
116 const std::pair<const_pointer, const_pointer>
f5886803 117 r_range = assert_node_consistent_(p_nd->m_p_right, __file, __line);
4569a895 118
8fc81078 119 if (r_range.first != 0)
f5886803 120 PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(p_nd->m_value),
47bea7b8 121 PB_DS_V2F(*r_range.first)));
4569a895 122
f5886803
FD
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);
4569a895
AT
125}
126
127PB_DS_CLASS_T_DEC
128void
129PB_DS_CLASS_C_DEC::
f5886803
FD
130assert_node_consistent_with_left(const node_pointer p_nd,
131 const char* __file, int __line) const
4569a895 132{
8fc81078 133 if (p_nd->m_p_left == 0)
4569a895 134 return;
f5886803
FD
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)));
4569a895
AT
138}
139
140PB_DS_CLASS_T_DEC
141void
142PB_DS_CLASS_C_DEC::
f5886803
FD
143assert_node_consistent_with_right(const node_pointer p_nd,
144 const char* __file, int __line) const
4569a895 145{
8fc81078 146 if (p_nd->m_p_right == 0)
4569a895 147 return;
f5886803
FD
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)));
4569a895
AT
151}
152
153PB_DS_CLASS_T_DEC
154void
155PB_DS_CLASS_C_DEC::
f5886803 156assert_min(const char* __file, int __line) const
4569a895 157{
f5886803 158 assert_min_imp(m_p_head->m_p_parent, __file, __line);
4569a895
AT
159}
160
161PB_DS_CLASS_T_DEC
162void
163PB_DS_CLASS_C_DEC::
f5886803 164assert_min_imp(const node_pointer p_nd, const char* __file, int __line) const
4569a895 165{
8fc81078 166 if (p_nd == 0)
4569a895 167 {
f5886803 168 PB_DS_DEBUG_VERIFY(m_p_head->m_p_left == m_p_head);
4569a895
AT
169 return;
170 }
171
8fc81078 172 if (p_nd->m_p_left == 0)
4569a895 173 {
f5886803 174 PB_DS_DEBUG_VERIFY(p_nd == m_p_head->m_p_left);
4569a895
AT
175 return;
176 }
f5886803 177 assert_min_imp(p_nd->m_p_left, __file, __line);
4569a895
AT
178}
179
180PB_DS_CLASS_T_DEC
181void
182PB_DS_CLASS_C_DEC::
f5886803 183assert_max(const char* __file, int __line) const
4569a895 184{
f5886803 185 assert_max_imp(m_p_head->m_p_parent, __file, __line);
4569a895
AT
186}
187
188PB_DS_CLASS_T_DEC
189void
190PB_DS_CLASS_C_DEC::
f5886803
FD
191assert_max_imp(const node_pointer p_nd,
192 const char* __file, int __line) const
4569a895 193{
8fc81078 194 if (p_nd == 0)
4569a895 195 {
f5886803 196 PB_DS_DEBUG_VERIFY(m_p_head->m_p_right == m_p_head);
4569a895
AT
197 return;
198 }
199
8fc81078 200 if (p_nd->m_p_right == 0)
4569a895 201 {
f5886803 202 PB_DS_DEBUG_VERIFY(p_nd == m_p_head->m_p_right);
4569a895
AT
203 return;
204 }
205
f5886803 206 assert_max_imp(p_nd->m_p_right, __file, __line);
4569a895
AT
207}
208
209PB_DS_CLASS_T_DEC
210void
211PB_DS_CLASS_C_DEC::
f5886803 212assert_iterators(const char* __file, int __line) const
4569a895
AT
213{
214 size_type iterated_num = 0;
4569a895 215 const_iterator prev_it = end();
4569a895
AT
216 for (const_iterator it = begin(); it != end(); ++it)
217 {
218 ++iterated_num;
f5886803 219 PB_DS_DEBUG_VERIFY(lower_bound(PB_DS_V2F(*it)).m_p_nd == it.m_p_nd);
47bea7b8 220 const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*it));
4569a895 221 --upper_bound_it;
f5886803 222 PB_DS_DEBUG_VERIFY(upper_bound_it.m_p_nd == it.m_p_nd);
4569a895
AT
223
224 if (prev_it != end())
f5886803
FD
225 PB_DS_DEBUG_VERIFY(Cmp_Fn::operator()(PB_DS_V2F(*prev_it),
226 PB_DS_V2F(*it)));
4569a895
AT
227 prev_it = it;
228 }
229
f5886803 230 PB_DS_DEBUG_VERIFY(iterated_num == m_size);
4569a895 231 size_type reverse_iterated_num = 0;
4569a895 232 const_reverse_iterator reverse_prev_it = rend();
4569a895
AT
233 for (const_reverse_iterator reverse_it = rbegin(); reverse_it != rend();
234 ++reverse_it)
235 {
236 ++reverse_iterated_num;
f5886803 237 PB_DS_DEBUG_VERIFY(lower_bound(
4569a895
AT
238 PB_DS_V2F(*reverse_it)).m_p_nd == reverse_it.m_p_nd);
239
47bea7b8 240 const_iterator upper_bound_it = upper_bound(PB_DS_V2F(*reverse_it));
4569a895 241 --upper_bound_it;
f5886803 242 PB_DS_DEBUG_VERIFY(upper_bound_it.m_p_nd == reverse_it.m_p_nd);
4569a895 243 if (reverse_prev_it != rend())
f5886803
FD
244 PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(PB_DS_V2F(*reverse_prev_it),
245 PB_DS_V2F(*reverse_it)));
4569a895
AT
246 reverse_prev_it = reverse_it;
247 }
f5886803 248 PB_DS_DEBUG_VERIFY(reverse_iterated_num == m_size);
4569a895
AT
249}
250
251PB_DS_CLASS_T_DEC
252void
253PB_DS_CLASS_C_DEC::
f5886803 254assert_consistent_with_debug_base(const char* __file, int __line) const
4569a895 255{
f5886803
FD
256 debug_base::check_size(m_size, __file, __line);
257 assert_consistent_with_debug_base(m_p_head->m_p_parent, __file, __line);
4569a895
AT
258}
259
260PB_DS_CLASS_T_DEC
261void
262PB_DS_CLASS_C_DEC::
f5886803
FD
263assert_consistent_with_debug_base(const node_pointer p_nd,
264 const char* __file, int __line) const
4569a895 265{
8fc81078 266 if (p_nd == 0)
4569a895 267 return;
f5886803
FD
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);
4569a895
AT
271}
272
273PB_DS_CLASS_T_DEC
274void
275PB_DS_CLASS_C_DEC::
f5886803 276assert_size(const char* __file, int __line) const
a345e45d 277{ PB_DS_DEBUG_VERIFY(recursive_count(m_p_head->m_p_parent) == m_size); }
4569a895 278
f5886803 279#endif
574dfb67 280#endif