47 #ifdef PB_DS_HT_MAP_TRACE_ 59 #ifdef PB_DS_DATA_TRUE_INDICATOR 60 #define PB_DS_GP_HASH_NAME gp_ht_map 63 #ifdef PB_DS_DATA_FALSE_INDICATOR 64 #define PB_DS_GP_HASH_NAME gp_ht_set 67 #define PB_DS_CLASS_T_DEC \ 68 template<typename Key, typename Mapped, typename Hash_Fn, typename Eq_Fn, \ 69 typename _Alloc, bool Store_Hash, typename Comb_Probe_Fn, \ 70 typename Probe_Fn, typename Resize_Policy> 72 #define PB_DS_CLASS_C_DEC \ 73 PB_DS_GP_HASH_NAME<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, \ 74 Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy> 76 #define PB_DS_HASH_EQ_FN_C_DEC \ 77 hash_eq_fn<Key, Eq_Fn, _Alloc, Store_Hash> 79 #define PB_DS_RANGED_PROBE_FN_C_DEC \ 80 ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, Store_Hash> 82 #define PB_DS_GP_HASH_TRAITS_BASE \ 83 types_traits<Key, Mapped, _Alloc, Store_Hash> 86 #define PB_DS_DEBUG_MAP_BASE_C_DEC \ 87 debug_map_base<Key, Eq_Fn, \ 88 typename _Alloc::template rebind<Key>::other::const_reference> 133 template<
typename Key,
139 typename Comb_Probe_Fn,
141 typename Resize_Policy>
142 class PB_DS_GP_HASH_NAME :
143 #ifdef _GLIBCXX_DEBUG 144 protected PB_DS_DEBUG_MAP_BASE_C_DEC,
146 public PB_DS_HASH_EQ_FN_C_DEC,
147 public Resize_Policy,
148 public PB_DS_RANGED_PROBE_FN_C_DEC,
149 public PB_DS_GP_HASH_TRAITS_BASE
153 typedef typename traits_base::value_type value_type_;
154 typedef typename traits_base::pointer pointer_;
155 typedef typename traits_base::const_pointer const_pointer_;
156 typedef typename traits_base::reference reference_;
157 typedef typename traits_base::const_reference const_reference_;
165 } __attribute__ ((__packed__));
167 struct entry :
public traits_base::stored_data_type
172 typedef typename _Alloc::template rebind<entry>::other entry_allocator;
173 typedef typename entry_allocator::pointer entry_pointer;
174 typedef typename entry_allocator::const_pointer const_entry_pointer;
175 typedef typename entry_allocator::reference entry_reference;
176 typedef typename entry_allocator::const_reference const_entry_reference;
177 typedef typename entry_allocator::pointer entry_array;
181 #ifdef _GLIBCXX_DEBUG 182 typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base;
186 typedef Resize_Policy resize_base;
188 #define PB_DS_GEN_POS typename _Alloc::size_type 198 typedef _Alloc allocator_type;
199 typedef typename _Alloc::size_type size_type;
200 typedef typename _Alloc::difference_type difference_type;
201 typedef Hash_Fn hash_fn;
203 typedef Probe_Fn probe_fn;
204 typedef Comb_Probe_Fn comb_probe_fn;
205 typedef Resize_Policy resize_policy;
210 store_hash = Store_Hash
213 typedef typename traits_base::key_type key_type;
214 typedef typename traits_base::key_pointer key_pointer;
215 typedef typename traits_base::key_const_pointer key_const_pointer;
216 typedef typename traits_base::key_reference key_reference;
217 typedef typename traits_base::key_const_reference key_const_reference;
218 typedef typename traits_base::mapped_type mapped_type;
219 typedef typename traits_base::mapped_pointer mapped_pointer;
220 typedef typename traits_base::mapped_const_pointer mapped_const_pointer;
221 typedef typename traits_base::mapped_reference mapped_reference;
222 typedef typename traits_base::mapped_const_reference mapped_const_reference;
223 typedef typename traits_base::value_type value_type;
224 typedef typename traits_base::pointer pointer;
225 typedef typename traits_base::const_pointer const_pointer;
226 typedef typename traits_base::reference reference;
227 typedef typename traits_base::const_reference const_reference;
229 #ifdef PB_DS_DATA_TRUE_INDICATOR 230 typedef point_iterator_ point_iterator;
233 #ifdef PB_DS_DATA_FALSE_INDICATOR 234 typedef point_const_iterator_ point_iterator;
237 typedef point_const_iterator_ point_const_iterator;
239 #ifdef PB_DS_DATA_TRUE_INDICATOR 240 typedef iterator_ iterator;
243 #ifdef PB_DS_DATA_FALSE_INDICATOR 244 typedef const_iterator_ iterator;
247 typedef const_iterator_ const_iterator;
249 PB_DS_GP_HASH_NAME();
251 PB_DS_GP_HASH_NAME(
const PB_DS_CLASS_C_DEC&);
253 PB_DS_GP_HASH_NAME(
const Hash_Fn&);
255 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&);
257 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Probe_Fn&);
259 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Probe_Fn&,
262 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Probe_Fn&,
263 const Probe_Fn&,
const Resize_Policy&);
265 template<
typename It>
267 copy_from_range(It, It);
270 ~PB_DS_GP_HASH_NAME();
273 swap(PB_DS_CLASS_C_DEC&);
307 get_probe_fn()
const;
315 get_comb_probe_fn()
const;
323 get_resize_policy()
const;
326 insert(const_reference r_val)
328 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid(__FILE__, __LINE__);)
329 return insert_imp(r_val, traits_base::m_store_extra_indicator);
332 inline mapped_reference
333 operator[](key_const_reference r_key)
335 #ifdef PB_DS_DATA_TRUE_INDICATOR 336 return subscript_imp(r_key, traits_base::m_store_extra_indicator);
339 return traits_base::s_null_type;
343 inline point_iterator
344 find(key_const_reference);
346 inline point_const_iterator
347 find(key_const_reference)
const;
349 inline point_iterator
352 inline point_const_iterator
356 erase(key_const_reference);
358 template<
typename Pred>
368 inline const_iterator
374 inline const_iterator
377 #ifdef _GLIBCXX_DEBUG 379 assert_valid(
const char*,
int)
const;
382 #ifdef PB_DS_HT_MAP_TRACE_ 388 #ifdef PB_DS_DATA_TRUE_INDICATOR 401 erase_all_valid_entries(entry_array, size_type);
404 do_resize_if_needed();
407 do_resize_if_needed_no_throw();
410 resize_imp(size_type);
413 do_resize(size_type);
416 resize_imp(entry_array, size_type);
419 resize_imp_reassign(entry_pointer, entry_array, false_type);
422 resize_imp_reassign(entry_pointer, entry_array, true_type);
425 find_ins_pos(key_const_reference, false_type);
428 find_ins_pos(key_const_reference, true_type);
431 insert_imp(const_reference, false_type);
434 insert_imp(const_reference, true_type);
437 insert_new_imp(const_reference r_val, size_type pos)
439 _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status);
441 if (do_resize_if_needed())
442 pos = find_ins_pos(PB_DS_V2F(r_val),
443 traits_base::m_store_extra_indicator);
445 _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status);
446 entry*
const p_e = m_entries + pos;
448 p_e->m_stat = valid_entry_status;
449 resize_base::notify_inserted(++m_num_used_e);
451 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(p_e->m_value));)
452 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
453 return &p_e->m_value;
457 insert_new_imp(const_reference r_val, comp_hash& r_pos_hash_pair)
459 _GLIBCXX_DEBUG_ASSERT(m_entries[r_pos_hash_pair.
first].m_stat !=
462 if (do_resize_if_needed())
463 r_pos_hash_pair = find_ins_pos(PB_DS_V2F(r_val),
464 traits_base::m_store_extra_indicator);
466 _GLIBCXX_DEBUG_ASSERT(m_entries[r_pos_hash_pair.
first].m_stat !=
469 entry*
const p_e = m_entries + r_pos_hash_pair.
first;
471 p_e->m_hash = r_pos_hash_pair.
second;
472 p_e->m_stat = valid_entry_status;
474 resize_base::notify_inserted(++m_num_used_e);
476 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(p_e->m_value));)
477 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
478 return &p_e->m_value;
481 #ifdef PB_DS_DATA_TRUE_INDICATOR 482 inline mapped_reference
483 subscript_imp(key_const_reference key, false_type)
485 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
487 const size_type pos = find_ins_pos(key,
488 traits_base::m_store_extra_indicator);
490 entry_pointer p_e = &m_entries[pos];
491 if (p_e->m_stat != valid_entry_status)
492 return insert_new_imp(
value_type(key, mapped_type()), pos)->second;
494 PB_DS_CHECK_KEY_EXISTS(key)
495 return p_e->m_value.second;
498 inline mapped_reference
499 subscript_imp(key_const_reference key, true_type)
501 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
503 comp_hash pos_hash_pair = find_ins_pos(key,
504 traits_base::m_store_extra_indicator);
506 if (m_entries[pos_hash_pair.first].m_stat != valid_entry_status)
507 return insert_new_imp(
value_type(key, mapped_type()),
508 pos_hash_pair)->second;
510 PB_DS_CHECK_KEY_EXISTS(key)
511 return (m_entries + pos_hash_pair.first)->m_value.second;
516 find_key_pointer(key_const_reference key, false_type)
518 const size_type hash = ranged_probe_fn_base::operator()(key);
519 resize_base::notify_find_search_start();
522 for (size_type i = 0; i < m_num_e; ++i)
524 const size_type pos = ranged_probe_fn_base::operator()(key,
527 entry*
const p_e = m_entries + pos;
530 case empty_entry_status:
532 resize_base::notify_find_search_end();
533 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
537 case valid_entry_status:
538 if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), key))
540 resize_base::notify_find_search_end();
541 PB_DS_CHECK_KEY_EXISTS(key)
545 case erased_entry_status:
548 _GLIBCXX_DEBUG_ASSERT(0);
551 resize_base::notify_find_search_collision();
554 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
555 resize_base::notify_find_search_end();
560 find_key_pointer(key_const_reference key, true_type)
562 comp_hash pos_hash_pair = ranged_probe_fn_base::operator()(key);
563 resize_base::notify_find_search_start();
566 for (size_type i = 0; i < m_num_e; ++i)
568 const size_type pos =
569 ranged_probe_fn_base::operator()(key, pos_hash_pair.
second, i);
571 entry*
const p_e = m_entries + pos;
575 case empty_entry_status:
577 resize_base::notify_find_search_end();
578 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
582 case valid_entry_status:
583 if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value),
585 key, pos_hash_pair.
second))
587 resize_base::notify_find_search_end();
588 PB_DS_CHECK_KEY_EXISTS(key)
592 case erased_entry_status:
595 _GLIBCXX_DEBUG_ASSERT(0);
598 resize_base::notify_find_search_collision();
601 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
602 resize_base::notify_find_search_end();
607 erase_imp(key_const_reference, true_type);
610 erase_imp(key_const_reference, false_type);
613 erase_entry(entry_pointer);
615 #ifdef PB_DS_DATA_TRUE_INDICATOR 617 inc_it_state(pointer& r_p_value, size_type& r_pos)
const 618 { inc_it_state((mapped_const_pointer& )r_p_value, r_pos); }
622 inc_it_state(const_pointer& r_p_value, size_type& r_pos)
const 624 _GLIBCXX_DEBUG_ASSERT(r_p_value != 0);
625 for (++r_pos; r_pos < m_num_e; ++r_pos)
627 const_entry_pointer p_e =& m_entries[r_pos];
628 if (p_e->m_stat == valid_entry_status)
630 r_p_value =& p_e->m_value;
638 get_start_it_state(const_pointer& r_p_value, size_type& r_pos)
const 640 for (r_pos = 0; r_pos < m_num_e; ++r_pos)
642 const_entry_pointer p_e = &m_entries[r_pos];
643 if (p_e->m_stat == valid_entry_status)
645 r_p_value = &p_e->m_value;
653 get_start_it_state(pointer& r_p_value, size_type& r_pos)
655 for (r_pos = 0; r_pos < m_num_e; ++r_pos)
657 entry_pointer p_e = &m_entries[r_pos];
658 if (p_e->m_stat == valid_entry_status)
660 r_p_value = &p_e->m_value;
667 #ifdef _GLIBCXX_DEBUG 669 assert_entry_array_valid(
const entry_array, false_type,
670 const char*,
int)
const;
673 assert_entry_array_valid(
const entry_array, true_type,
674 const char*,
int)
const;
677 static entry_allocator s_entry_allocator;
678 static iterator s_end_it;
679 static const_iterator s_const_end_it;
682 size_type m_num_used_e;
683 entry_pointer m_entries;
687 store_hash_ok = !Store_Hash
688 || !is_same<Hash_Fn, __gnu_pbds::null_type>::value
691 PB_DS_STATIC_ASSERT(sth, store_hash_ok);
705 #undef PB_DS_CLASS_T_DEC 706 #undef PB_DS_CLASS_C_DEC 707 #undef PB_DS_HASH_EQ_FN_C_DEC 708 #undef PB_DS_RANGED_PROBE_FN_C_DEC 709 #undef PB_DS_GP_HASH_TRAITS_BASE 710 #undef PB_DS_DEBUG_MAP_BASE_C_DEC 711 #undef PB_DS_GP_HASH_NAME
GNU extensions for policy-based data structures for public use.
Traits for abstract types.
iterator_()
Default constructor.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
pointer_ pointer
Iterator's pointer type.
_T2 second
first is a copy of the first object
const_iterator_()
Default constructor.
Struct holding two objects of arbitrary type.
_T1 first
second_type is the second bound type
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
value_type_ value_type
Iterator's value type.