41 #ifndef PB_DS_DEBUG_MAP_BASE_HPP
42 #define PB_DS_DEBUG_MAP_BASE_HPP
58 template<
typename _CharT,
typename _Traits,
typename _Tp1,
typename _Tp2>
62 {
return (__out <<
'(' << p.
first <<
',' << p.
second <<
')'); }
64 #define PB_DS_CLASS_T_DEC \
65 template<typename Key, typename Eq_Fn, typename Const_Key_Reference>
67 #define PB_DS_CLASS_C_DEC \
68 debug_map_base<Key, Eq_Fn, Const_Key_Reference>
71 template<
typename Key,
typename Eq_Fn,
typename Const_Key_Reference>
75 typedef Const_Key_Reference key_const_reference;
76 typedef std::_GLIBCXX_STD_C::list<Key> key_repository;
77 typedef typename key_repository::size_type size_type;
78 typedef typename key_repository::iterator iterator;
79 typedef typename key_repository::const_iterator const_iterator;
84 debug_map_base(
const PB_DS_CLASS_C_DEC&);
89 insert_new(key_const_reference);
92 erase_existing(key_const_reference);
98 check_key_exists(key_const_reference,
const char*,
int)
const;
101 check_key_does_not_exist(key_const_reference,
const char*,
int)
const;
104 check_size(size_type,
const char*,
int)
const;
107 swap(PB_DS_CLASS_C_DEC&);
109 template<
typename Cmp_Fn>
111 split(key_const_reference, Cmp_Fn, PB_DS_CLASS_C_DEC&);
114 join(PB_DS_CLASS_C_DEC&,
bool with_cleanup =
true);
118 assert_valid(
const char*,
int)
const;
121 find(key_const_reference)
const;
124 find(key_const_reference);
126 key_repository m_keys;
133 { PB_DS_ASSERT_VALID((*
this)) }
137 debug_map_base(
const PB_DS_CLASS_C_DEC& other)
138 : m_keys(other.m_keys), m_eq(other.m_eq)
139 { PB_DS_ASSERT_VALID((*
this)) }
144 { PB_DS_ASSERT_VALID((*
this)) }
149 insert_new(key_const_reference r_key)
151 PB_DS_ASSERT_VALID((*
this))
153 if (find(r_key) != m_keys.
end())
161 m_keys.push_back(r_key);
169 PB_DS_ASSERT_VALID((*
this))
175 erase_existing(key_const_reference r_key)
177 PB_DS_ASSERT_VALID((*
this))
178 iterator it = find(r_key);
179 if (it == m_keys.
end())
185 PB_DS_ASSERT_VALID((*
this))
193 PB_DS_ASSERT_VALID((*
this))
195 PB_DS_ASSERT_VALID((*this))
201 check_key_exists(key_const_reference r_key,
202 const
char* __file,
int __line)
const
204 assert_valid(__file, __line);
205 if (find(r_key) == m_keys.end())
207 std::cerr << __file <<
':' << __line <<
": check_key_exists "
216 check_key_does_not_exist(key_const_reference r_key,
217 const char* __file,
int __line)
const
219 assert_valid(__file, __line);
220 if (find(r_key) != m_keys.end())
224 cerr << __file <<
':' << __line <<
": check_key_does_not_exist "
233 check_size(size_type size,
const char* __file,
int __line)
const
235 assert_valid(__file, __line);
236 const size_type keys_size = m_keys.size();
237 if (size != keys_size)
239 std::cerr << __file <<
':' << __line <<
": check_size "
240 << size <<
" != " << keys_size <<
std::endl;
248 swap(PB_DS_CLASS_C_DEC& other)
250 PB_DS_ASSERT_VALID((*
this))
251 m_keys.
swap(other.m_keys);
253 PB_DS_ASSERT_VALID((*this))
257 typename PB_DS_CLASS_C_DEC::const_iterator
259 find(key_const_reference r_key)
const
261 PB_DS_ASSERT_VALID((*
this))
262 typedef const_iterator iterator_type;
263 for (iterator_type it = m_keys.
begin(); it != m_keys.
end(); ++it)
264 if (m_eq(*it, r_key))
270 typename PB_DS_CLASS_C_DEC::iterator
272 find(key_const_reference r_key)
274 PB_DS_ASSERT_VALID((*
this))
275 iterator it = m_keys.
begin();
276 while (it != m_keys.
end())
278 if (m_eq(*it, r_key))
288 assert_valid(
const char* __file,
int __line)
const
290 const_iterator prime_it = m_keys.begin();
291 while (prime_it != m_keys.end())
293 const_iterator sec_it = prime_it;
295 while (sec_it != m_keys.end())
297 PB_DS_DEBUG_VERIFY(!m_eq(*sec_it, *prime_it));
298 PB_DS_DEBUG_VERIFY(!m_eq(*prime_it, *sec_it));
306 template<
typename Cmp_Fn>
309 split(key_const_reference r_key, Cmp_Fn cmp_fn, PB_DS_CLASS_C_DEC& other)
312 iterator it = m_keys.begin();
313 while (it != m_keys.end())
314 if (cmp_fn(r_key, *it))
316 other.insert_new(*it);
317 it = m_keys.erase(it);
326 join(PB_DS_CLASS_C_DEC& other,
bool with_cleanup)
328 iterator it = other.m_keys.begin();
329 while (it != other.m_keys.end())
333 it = other.m_keys.erase(it);
337 _GLIBCXX_DEBUG_ASSERT(!with_cleanup || other.m_keys.empty());
340 #undef PB_DS_CLASS_T_DEC
341 #undef PB_DS_CLASS_C_DEC
void swap(shared_lock< _Mutex > &__x, shared_lock< _Mutex > &__y) noexcept
Swap specialization for shared_lock.
ISO C++ entities toplevel namespace is std.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
ostream cerr
Linked to standard output.
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
Write a newline and flush the stream.
GNU extensions for policy-based data structures for public use.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list.
Template class basic_ostream.
Struct holding two objects of arbitrary type.
_T1 first
The first member.
_T2 second
The second member.