42 #define PB_DS_ASSERT_VALID(X) \
43 _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);)
47 hash_load_check_resize_trigger(
float load_min,
float load_max)
48 : m_load_min(load_min), m_load_max(load_max), m_next_shrink_size(0),
49 m_next_grow_size(0), m_resize_needed(false)
50 { PB_DS_ASSERT_VALID((*
this)) }
55 notify_find_search_start()
56 { PB_DS_ASSERT_VALID((*
this)) }
61 notify_find_search_collision()
62 { PB_DS_ASSERT_VALID((*
this)) }
67 notify_find_search_end()
68 { PB_DS_ASSERT_VALID((*
this)) }
73 notify_insert_search_start()
74 { PB_DS_ASSERT_VALID((*
this)) }
79 notify_insert_search_collision()
80 { PB_DS_ASSERT_VALID((*
this)) }
85 notify_insert_search_end()
86 { PB_DS_ASSERT_VALID((*
this)) }
91 notify_erase_search_start()
92 { PB_DS_ASSERT_VALID((*
this)) }
97 notify_erase_search_collision()
98 { PB_DS_ASSERT_VALID((*
this)) }
103 notify_erase_search_end()
104 { PB_DS_ASSERT_VALID((*
this)) }
109 notify_inserted(size_type num_entries)
111 m_resize_needed = (num_entries >= m_next_grow_size);
112 size_base::set_size(num_entries);
113 PB_DS_ASSERT_VALID((*
this))
119 notify_erased(size_type num_entries)
121 size_base::set_size(num_entries);
122 m_resize_needed = num_entries <= m_next_shrink_size;
123 PB_DS_ASSERT_VALID((*
this))
129 is_resize_needed()
const
131 PB_DS_ASSERT_VALID((*
this))
132 return m_resize_needed;
138 is_grow_needed(size_type , size_type num_entries)
const
140 _GLIBCXX_DEBUG_ASSERT(m_resize_needed);
141 return num_entries >= m_next_grow_size;
146 ~hash_load_check_resize_trigger() { }
151 notify_resized(size_type new_size)
153 m_resize_needed =
false;
154 m_next_grow_size = size_type(m_load_max * new_size - 1);
155 m_next_shrink_size = size_type(m_load_min * new_size);
157 #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
162 <<
"4 " << m_next_shrink_size <<
std::endl
163 <<
"5 " << m_next_grow_size <<
std::endl;
166 PB_DS_ASSERT_VALID((*
this))
172 notify_externally_resized(size_type new_size)
174 m_resize_needed =
false;
175 size_type new_grow_size = size_type(m_load_max * new_size - 1);
176 size_type new_shrink_size = size_type(m_load_min * new_size);
178 #ifdef PB_DS_HT_MAP_RESIZE_TRACE_
179 std::cerr <<
"hlcrt::notify_externally_resized " << std::endl
180 <<
"1 " << new_size << std::endl
181 <<
"2 " << m_load_min << std::endl
182 <<
"3 " << m_load_max << std::endl
183 <<
"4 " << m_next_shrink_size << std::endl
184 <<
"5 " << m_next_grow_size << std::endl
185 <<
"6 " << new_shrink_size << std::endl
189 if (new_grow_size >= m_next_grow_size)
191 _GLIBCXX_DEBUG_ASSERT(new_shrink_size >= m_next_shrink_size);
192 m_next_grow_size = new_grow_size;
196 _GLIBCXX_DEBUG_ASSERT(new_shrink_size <= m_next_shrink_size);
197 m_next_shrink_size = new_shrink_size;
200 PB_DS_ASSERT_VALID((*
this))
208 PB_DS_ASSERT_VALID((*
this))
209 size_base::set_size(0);
210 m_resize_needed = (0 < m_next_shrink_size);
211 PB_DS_ASSERT_VALID((*this))
217 swap(PB_DS_CLASS_C_DEC& other)
219 PB_DS_ASSERT_VALID((*
this))
220 PB_DS_ASSERT_VALID(other)
222 size_base::swap(other);
223 std::swap(m_load_min, other.m_load_min);
224 std::swap(m_load_max, other.m_load_max);
225 std::swap(m_resize_needed, other.m_resize_needed);
226 std::swap(m_next_grow_size, other.m_next_grow_size);
227 std::swap(m_next_shrink_size, other.m_next_shrink_size);
229 PB_DS_ASSERT_VALID((*this))
230 PB_DS_ASSERT_VALID(other)
234 inline std::pair<
float,
float>
238 PB_DS_STATIC_ASSERT(access, external_load_access);
247 PB_DS_STATIC_ASSERT(access, external_load_access);
248 const float old_load_min = m_load_min;
249 const float old_load_max = m_load_max;
250 const size_type old_next_shrink_size = m_next_shrink_size;
251 const size_type old_next_grow_size = m_next_grow_size;
252 const bool old_resize_needed = m_resize_needed;
256 m_load_min = load_pair.
first;
257 m_load_max = load_pair.
second;
258 do_resize(static_cast<size_type>(size_base::get_size() / ((m_load_min + m_load_max) / 2)));
262 m_load_min = old_load_min;
263 m_load_max = old_load_max;
264 m_next_shrink_size = old_next_shrink_size;
265 m_next_grow_size = old_next_grow_size;
266 m_resize_needed = old_resize_needed;
267 __throw_exception_again;
277 #ifdef _GLIBCXX_DEBUG
278 # define PB_DS_DEBUG_VERIFY(_Cond) \
279 _GLIBCXX_DEBUG_VERIFY_AT(_Cond, \
280 _M_message(#_Cond" assertion from %1;:%2;") \
281 ._M_string(__FILE__)._M_integer(__LINE__) \
287 assert_valid(
const char* __file,
int __line)
const
289 PB_DS_DEBUG_VERIFY(m_load_max > m_load_min);
290 PB_DS_DEBUG_VERIFY(m_next_grow_size >= m_next_shrink_size);
292 # undef PB_DS_DEBUG_VERIFY
294 #undef PB_DS_ASSERT_VALID
_T1 first
second_type is the second bound type
_T2 second
first is a copy of the first object
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
Write a newline and flush the stream.
ostream cerr
Linked to standard output.
Struct holding two objects of arbitrary type.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.