48 #ifdef PB_DS_HT_MAP_TRACE_
60 #ifdef PB_DS_DATA_TRUE_INDICATOR
61 #define PB_DS_GP_HASH_NAME gp_ht_map
64 #ifdef PB_DS_DATA_FALSE_INDICATOR
65 #define PB_DS_GP_HASH_NAME gp_ht_set
68 #define PB_DS_CLASS_T_DEC \
69 template<typename Key, typename Mapped, typename Hash_Fn, typename Eq_Fn, \
70 typename _Alloc, bool Store_Hash, typename Comb_Probe_Fn, \
71 typename Probe_Fn, typename Resize_Policy>
73 #define PB_DS_CLASS_C_DEC \
74 PB_DS_GP_HASH_NAME<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, \
75 Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>
77 #define PB_DS_HASH_EQ_FN_C_DEC \
78 hash_eq_fn<Key, Eq_Fn, _Alloc, Store_Hash>
80 #define PB_DS_RANGED_PROBE_FN_C_DEC \
81 ranged_probe_fn<Key, Hash_Fn, _Alloc, Comb_Probe_Fn, Probe_Fn, Store_Hash>
83 #define PB_DS_GP_HASH_TRAITS_BASE \
84 types_traits<Key, Mapped, _Alloc, Store_Hash>
87 #define PB_DS_DEBUG_MAP_BASE_C_DEC \
88 debug_map_base<Key, Eq_Fn, \
89 typename _Alloc::template rebind<Key>::other::const_reference>
134 template<
typename Key,
140 typename Comb_Probe_Fn,
142 typename Resize_Policy>
143 class PB_DS_GP_HASH_NAME :
144 #ifdef _GLIBCXX_DEBUG
145 protected PB_DS_DEBUG_MAP_BASE_C_DEC,
147 public PB_DS_HASH_EQ_FN_C_DEC,
148 public Resize_Policy,
149 public PB_DS_RANGED_PROBE_FN_C_DEC,
150 public PB_DS_GP_HASH_TRAITS_BASE
154 typedef typename traits_base::value_type value_type_;
155 typedef typename traits_base::pointer pointer_;
156 typedef typename traits_base::const_pointer const_pointer_;
157 typedef typename traits_base::reference reference_;
158 typedef typename traits_base::const_reference const_reference_;
166 } __attribute__ ((packed));
168 struct entry :
public traits_base::stored_data_type
173 typedef typename _Alloc::template rebind<entry>::other entry_allocator;
174 typedef typename entry_allocator::pointer entry_pointer;
175 typedef typename entry_allocator::const_pointer const_entry_pointer;
176 typedef typename entry_allocator::reference entry_reference;
177 typedef typename entry_allocator::const_reference const_entry_reference;
178 typedef typename entry_allocator::pointer entry_array;
182 #ifdef _GLIBCXX_DEBUG
183 typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base;
187 typedef Resize_Policy resize_base;
189 #define PB_DS_GEN_POS typename _Alloc::size_type
199 typedef _Alloc allocator_type;
200 typedef typename _Alloc::size_type size_type;
201 typedef typename _Alloc::difference_type difference_type;
202 typedef Hash_Fn hash_fn;
204 typedef Probe_Fn probe_fn;
205 typedef Comb_Probe_Fn comb_probe_fn;
206 typedef Resize_Policy resize_policy;
211 store_hash = Store_Hash
214 typedef typename traits_base::key_type key_type;
215 typedef typename traits_base::key_pointer key_pointer;
216 typedef typename traits_base::key_const_pointer key_const_pointer;
217 typedef typename traits_base::key_reference key_reference;
218 typedef typename traits_base::key_const_reference key_const_reference;
219 typedef typename traits_base::mapped_type mapped_type;
220 typedef typename traits_base::mapped_pointer mapped_pointer;
221 typedef typename traits_base::mapped_const_pointer mapped_const_pointer;
222 typedef typename traits_base::mapped_reference mapped_reference;
223 typedef typename traits_base::mapped_const_reference mapped_const_reference;
224 typedef typename traits_base::value_type value_type;
225 typedef typename traits_base::pointer pointer;
226 typedef typename traits_base::const_pointer const_pointer;
227 typedef typename traits_base::reference reference;
228 typedef typename traits_base::const_reference const_reference;
230 #ifdef PB_DS_DATA_TRUE_INDICATOR
231 typedef point_iterator_ point_iterator;
234 #ifdef PB_DS_DATA_FALSE_INDICATOR
235 typedef point_const_iterator_ point_iterator;
238 typedef point_const_iterator_ point_const_iterator;
240 #ifdef PB_DS_DATA_TRUE_INDICATOR
241 typedef iterator_ iterator;
244 #ifdef PB_DS_DATA_FALSE_INDICATOR
245 typedef const_iterator_ iterator;
248 typedef const_iterator_ const_iterator;
250 PB_DS_GP_HASH_NAME();
252 PB_DS_GP_HASH_NAME(
const PB_DS_CLASS_C_DEC&);
254 PB_DS_GP_HASH_NAME(
const Hash_Fn&);
256 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&);
258 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Probe_Fn&);
260 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Probe_Fn&,
263 PB_DS_GP_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Probe_Fn&,
264 const Probe_Fn&,
const Resize_Policy&);
266 template<
typename It>
268 copy_from_range(It, It);
271 ~PB_DS_GP_HASH_NAME();
274 swap(PB_DS_CLASS_C_DEC&);
308 get_probe_fn()
const;
316 get_comb_probe_fn()
const;
324 get_resize_policy()
const;
327 insert(const_reference r_val)
329 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid(__FILE__, __LINE__);)
330 return insert_imp(r_val, traits_base::m_store_extra_indicator);
333 inline mapped_reference
336 #ifdef PB_DS_DATA_TRUE_INDICATOR
337 return subscript_imp(r_key, traits_base::m_store_extra_indicator);
340 return traits_base::s_null_type;
344 inline point_iterator
345 find(key_const_reference);
347 inline point_const_iterator
348 find(key_const_reference)
const;
350 inline point_iterator
353 inline point_const_iterator
357 erase(key_const_reference);
359 template<
typename Pred>
369 inline const_iterator
375 inline const_iterator
378 #ifdef _GLIBCXX_DEBUG
380 assert_valid(
const char*,
int)
const;
383 #ifdef PB_DS_HT_MAP_TRACE_
389 #ifdef PB_DS_DATA_TRUE_INDICATOR
402 erase_all_valid_entries(entry_array, size_type);
405 do_resize_if_needed();
408 do_resize_if_needed_no_throw();
411 resize_imp(size_type);
414 do_resize(size_type);
417 resize_imp(entry_array, size_type);
420 resize_imp_reassign(entry_pointer, entry_array, false_type);
423 resize_imp_reassign(entry_pointer, entry_array, true_type);
426 find_ins_pos(key_const_reference, false_type);
429 find_ins_pos(key_const_reference, true_type);
432 insert_imp(const_reference, false_type);
435 insert_imp(const_reference, true_type);
438 insert_new_imp(const_reference r_val, size_type pos)
440 _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status);
442 if (do_resize_if_needed())
443 pos = find_ins_pos(PB_DS_V2F(r_val),
444 traits_base::m_store_extra_indicator);
446 _GLIBCXX_DEBUG_ASSERT(m_entries[pos].m_stat != valid_entry_status);
447 entry*
const p_e = m_entries + pos;
449 p_e->m_stat = valid_entry_status;
450 resize_base::notify_inserted(++m_num_used_e);
452 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(p_e->m_value));)
453 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
454 return &p_e->m_value;
458 insert_new_imp(const_reference r_val,
comp_hash& r_pos_hash_pair)
460 _GLIBCXX_DEBUG_ASSERT(m_entries[r_pos_hash_pair.
first].m_stat !=
463 if (do_resize_if_needed())
464 r_pos_hash_pair = find_ins_pos(PB_DS_V2F(r_val),
465 traits_base::m_store_extra_indicator);
467 _GLIBCXX_DEBUG_ASSERT(m_entries[r_pos_hash_pair.
first].m_stat !=
470 entry*
const p_e = m_entries + r_pos_hash_pair.
first;
472 p_e->m_hash = r_pos_hash_pair.
second;
473 p_e->m_stat = valid_entry_status;
475 resize_base::notify_inserted(++m_num_used_e);
477 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(p_e->m_value));)
478 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
479 return &p_e->m_value;
482 #ifdef PB_DS_DATA_TRUE_INDICATOR
483 inline mapped_reference
484 subscript_imp(key_const_reference key, false_type)
486 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
488 const size_type pos = find_ins_pos(key,
489 traits_base::m_store_extra_indicator);
491 entry_pointer p_e = &m_entries[pos];
492 if (p_e->m_stat != valid_entry_status)
493 return insert_new_imp(
value_type(key, mapped_type()), pos)->second;
495 PB_DS_CHECK_KEY_EXISTS(key)
496 return p_e->m_value.second;
499 inline mapped_reference
500 subscript_imp(key_const_reference key, true_type)
502 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
504 comp_hash pos_hash_pair = find_ins_pos(key,
505 traits_base::m_store_extra_indicator);
507 if (m_entries[pos_hash_pair.first].m_stat != valid_entry_status)
508 return insert_new_imp(
value_type(key, mapped_type()),
509 pos_hash_pair)->second;
511 PB_DS_CHECK_KEY_EXISTS(key)
512 return (m_entries + pos_hash_pair.first)->m_value.second;
517 find_key_pointer(key_const_reference key, false_type)
519 const size_type hash = ranged_probe_fn_base::operator()(key);
520 resize_base::notify_find_search_start();
523 for (size_type i = 0; i < m_num_e; ++i)
525 const size_type pos = ranged_probe_fn_base::operator()(key,
528 entry*
const p_e = m_entries + pos;
531 case empty_entry_status:
533 resize_base::notify_find_search_end();
534 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
538 case valid_entry_status:
539 if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), key))
541 resize_base::notify_find_search_end();
542 PB_DS_CHECK_KEY_EXISTS(key)
546 case erased_entry_status:
549 _GLIBCXX_DEBUG_ASSERT(0);
552 resize_base::notify_find_search_collision();
555 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
556 resize_base::notify_find_search_end();
561 find_key_pointer(key_const_reference key, true_type)
563 comp_hash pos_hash_pair = ranged_probe_fn_base::operator()(key);
564 resize_base::notify_find_search_start();
567 for (size_type i = 0; i < m_num_e; ++i)
569 const size_type pos =
570 ranged_probe_fn_base::operator()(key, pos_hash_pair.
second, i);
572 entry*
const p_e = m_entries + pos;
576 case empty_entry_status:
578 resize_base::notify_find_search_end();
579 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
583 case valid_entry_status:
584 if (hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value),
586 key, pos_hash_pair.
second))
588 resize_base::notify_find_search_end();
589 PB_DS_CHECK_KEY_EXISTS(key)
593 case erased_entry_status:
596 _GLIBCXX_DEBUG_ASSERT(0);
599 resize_base::notify_find_search_collision();
602 PB_DS_CHECK_KEY_DOES_NOT_EXIST(key)
603 resize_base::notify_find_search_end();
608 erase_imp(key_const_reference, true_type);
611 erase_imp(key_const_reference, false_type);
614 erase_entry(entry_pointer);
616 #ifdef PB_DS_DATA_TRUE_INDICATOR
618 inc_it_state(pointer& r_p_value, size_type& r_pos)
const
619 { inc_it_state((mapped_const_pointer& )r_p_value, r_pos); }
623 inc_it_state(const_pointer& r_p_value, size_type& r_pos)
const
625 _GLIBCXX_DEBUG_ASSERT(r_p_value != 0);
626 for (++r_pos; r_pos < m_num_e; ++r_pos)
628 const_entry_pointer p_e =& m_entries[r_pos];
629 if (p_e->m_stat == valid_entry_status)
631 r_p_value =& p_e->m_value;
639 get_start_it_state(const_pointer& r_p_value, size_type& r_pos)
const
641 for (r_pos = 0; r_pos < m_num_e; ++r_pos)
643 const_entry_pointer p_e = &m_entries[r_pos];
644 if (p_e->m_stat == valid_entry_status)
646 r_p_value = &p_e->m_value;
654 get_start_it_state(pointer& r_p_value, size_type& r_pos)
656 for (r_pos = 0; r_pos < m_num_e; ++r_pos)
658 entry_pointer p_e = &m_entries[r_pos];
659 if (p_e->m_stat == valid_entry_status)
661 r_p_value = &p_e->m_value;
668 #ifdef _GLIBCXX_DEBUG
670 assert_entry_array_valid(
const entry_array, false_type,
671 const char*,
int)
const;
674 assert_entry_array_valid(
const entry_array, true_type,
675 const char*,
int)
const;
678 static entry_allocator s_entry_allocator;
679 static iterator s_end_it;
680 static const_iterator s_const_end_it;
683 size_type m_num_used_e;
684 entry_pointer m_entries;
688 store_hash_ok = !Store_Hash
689 || !is_same<Hash_Fn, __gnu_pbds::null_type>::value
692 PB_DS_STATIC_ASSERT(sth, store_hash_ok);
706 #undef PB_DS_CLASS_T_DEC
707 #undef PB_DS_CLASS_C_DEC
708 #undef PB_DS_HASH_EQ_FN_C_DEC
709 #undef PB_DS_RANGED_PROBE_FN_C_DEC
710 #undef PB_DS_GP_HASH_TRAITS_BASE
711 #undef PB_DS_DEBUG_MAP_BASE_C_DEC
712 #undef PB_DS_GP_HASH_NAME
value_type_ value_type
Iterator's value type.
_T1 first
second_type is the second bound type
_T2 second
first is a copy of the first object
pointer_ pointer
Iterator's pointer type.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initilizer_list.
iterator_()
Default constructor.
reference operator[](size_t __position)
Array-indexing support.
Struct holding two objects of arbitrary type.
Traits for abstract types.
const_iterator_()
Default constructor.
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initilizer_list.
constexpr size_t size() const _GLIBCXX_NOEXCEPT
Returns the total number of bits.