libstdc++
binomial_heap_base_/debug_fn_imps.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the terms
8 // of the GNU General Public License as published by the Free Software
9 // Foundation; either version 3, or (at your option) any later
10 // version.
11 
12 // This library is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
16 
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20 
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
25 
26 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 
28 // Permission to use, copy, modify, sell, and distribute this software
29 // is hereby granted without fee, provided that the above copyright
30 // notice appears in all copies, and that both that copyright notice
31 // and this permission notice appear in supporting documentation. None
32 // of the above authors, nor IBM Haifa Research Laboratories, make any
33 // representation about the suitability of this software for any
34 // purpose. It is provided "as is" without express or implied
35 // warranty.
36 
37 /**
38  * @file binomial_heap_base_/debug_fn_imps.hpp
39  * Contains an implementation class for a base of binomial heaps.
40  */
41 
42 #ifdef _GLIBCXX_DEBUG
43 
44 PB_DS_CLASS_T_DEC
45 void
46 PB_DS_CLASS_C_DEC::
47 assert_valid(bool strictly_binomial, const char* __file, int __line) const
48 {
49  base_type::assert_valid(__file, __line);
50  assert_node_consistent(base_type::m_p_root, strictly_binomial, true,
51  __file, __line);
52  assert_max(__file, __line);
53 }
54 
55 PB_DS_CLASS_T_DEC
56 void
57 PB_DS_CLASS_C_DEC::
58 assert_max(const char* __file, int __line) const
59 {
60  if (m_p_max == 0)
61  return;
62  PB_DS_DEBUG_VERIFY(base_type::parent(m_p_max) == 0);
63  for (const_iterator it = base_type::begin(); it != base_type::end(); ++it)
64  PB_DS_DEBUG_VERIFY(!Cmp_Fn::operator()(m_p_max->m_value,
65  it.m_p_nd->m_value));
66 }
67 
68 PB_DS_CLASS_T_DEC
69 void
70 PB_DS_CLASS_C_DEC::
71 assert_node_consistent(node_const_pointer p_nd, bool strictly_binomial,
72  bool increasing, const char* __file, int __line) const
73 {
74  PB_DS_DEBUG_VERIFY(increasing || strictly_binomial);
75  base_type::assert_node_consistent(p_nd, false, __file, __line);
76  if (p_nd == 0)
77  return;
78  PB_DS_DEBUG_VERIFY(p_nd->m_metadata == base_type::degree(p_nd));
79  PB_DS_DEBUG_VERIFY(base_type::size_under_node(p_nd) ==
80  static_cast<size_type>(1 << p_nd->m_metadata));
81  assert_node_consistent(p_nd->m_p_next_sibling, strictly_binomial, increasing,
82  __file, __line);
83  assert_node_consistent(p_nd->m_p_l_child, true, false, __file, __line);
84  if (p_nd->m_p_next_sibling != 0)
85  {
86  if (increasing)
87  {
88  if (strictly_binomial)
89  PB_DS_DEBUG_VERIFY(p_nd->m_metadata
90  < p_nd->m_p_next_sibling->m_metadata);
91  else
92  PB_DS_DEBUG_VERIFY(p_nd->m_metadata
93  <= p_nd->m_p_next_sibling->m_metadata);
94  }
95  else
96  PB_DS_DEBUG_VERIFY(p_nd->m_metadata
97  > p_nd->m_p_next_sibling->m_metadata);
98  }
99 }
100 
101 #endif
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initilizer_list.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initilizer_list.