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 rebind_traits<_Alloc, Key>::const_reference>
133 template<
typename Key,
139 typename Comb_Probe_Fn,
141 typename Resize_Policy>
142 class PB_DS_GP_HASH_NAME :
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
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__));
173 typedef typename entry_traits::allocator_type entry_allocator;
174 typedef typename entry_traits::pointer entry_pointer;
175 typedef typename entry_traits::const_pointer const_entry_pointer;
176 typedef typename entry_traits::reference entry_reference;
177 typedef typename entry_traits::const_reference const_entry_reference;
178 typedef typename entry_traits::pointer entry_array;
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;
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&);
283 _GLIBCXX_NODISCARD
inline bool
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
334 operator[](key_const_reference r_key)
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
380 assert_valid(
const char*,
int)
const;
383#ifdef PB_DS_HT_MAP_TRACE_
389#ifdef PB_DS_DATA_TRUE_INDICATOR
390 friend class iterator_;
393 friend class const_iterator_;
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;
448 new (&p_e->m_value) value_type(r_val);
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;
471 new (&p_e->m_value) value_type(r_val);
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)
543 return pointer(&p_e->m_value);
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)
590 return pointer(&p_e->m_value);
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;
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
GNU extensions for policy-based data structures for public use.
Struct holding two objects of arbitrary type.
Primary template for representation of stored data. Two types of data can be stored: value and hash.
Consistent API for accessing allocator-related types.
Traits for abstract types.
bool empty() const
True if size() == 0.
Comb_Probe_Fn & get_comb_probe_fn()
Return current comb_probe_fn.
const Comb_Probe_Fn & get_comb_probe_fn() const
Return current const comb_probe_fn.
const Hash_Fn & get_hash_fn() const
Return current const hash_fn.
Resize_Policy & get_resize_policy()
Return current resize_policy.
Eq_Fn & get_eq_fn()
Return current eq_fn.
const Eq_Fn & get_eq_fn() const
Return current const eq_fn.
Probe_Fn & get_probe_fn()
Return current probe_fn.
const Resize_Policy & get_resize_policy() const
Return current const resize_policy.
Hash_Fn & get_hash_fn()
Return current hash_fn.
const Probe_Fn & get_probe_fn() const
Return current const probe_fn.