53 #ifdef PB_DS_HT_MAP_TRACE_
62 #ifdef PB_DS_DATA_TRUE_INDICATOR
63 #define PB_DS_CC_HASH_NAME cc_ht_map
66 #ifdef PB_DS_DATA_FALSE_INDICATOR
67 #define PB_DS_CC_HASH_NAME cc_ht_set
70 #define PB_DS_CLASS_T_DEC \
71 template<typename Key, typename Mapped, typename Hash_Fn, \
72 typename Eq_Fn, typename _Alloc, bool Store_Hash, \
73 typename Comb_Hash_Fn, typename Resize_Policy>
75 #define PB_DS_CLASS_C_DEC \
76 PB_DS_CC_HASH_NAME<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, \
77 Store_Hash, Comb_Hash_Fn, Resize_Policy>
79 #define PB_DS_HASH_EQ_FN_C_DEC \
80 hash_eq_fn<Key, Eq_Fn, _Alloc, Store_Hash>
82 #define PB_DS_RANGED_HASH_FN_C_DEC \
83 ranged_hash_fn<Key, Hash_Fn, _Alloc, Comb_Hash_Fn, Store_Hash>
85 #define PB_DS_CC_HASH_TRAITS_BASE \
86 types_traits<Key, Mapped, _Alloc, Store_Hash>
89 #define PB_DS_DEBUG_MAP_BASE_C_DEC \
90 debug_map_base<Key, Eq_Fn, \
91 typename _Alloc::template rebind<Key>::other::const_reference>
132 template<
typename Key,
138 typename Comb_Hash_Fn,
139 typename Resize_Policy >
140 class PB_DS_CC_HASH_NAME:
141 #ifdef _GLIBCXX_DEBUG
142 protected PB_DS_DEBUG_MAP_BASE_C_DEC,
144 public PB_DS_HASH_EQ_FN_C_DEC,
145 public Resize_Policy,
146 public PB_DS_RANGED_HASH_FN_C_DEC,
147 public PB_DS_CC_HASH_TRAITS_BASE
152 typedef typename traits_base::value_type value_type_;
153 typedef typename traits_base::pointer pointer_;
154 typedef typename traits_base::const_pointer const_pointer_;
155 typedef typename traits_base::reference reference_;
156 typedef typename traits_base::const_reference const_reference_;
158 struct entry :
public traits_base::stored_data_type
160 typename _Alloc::template rebind<entry>::other::pointer m_p_next;
165 typedef typename _Alloc::template rebind<entry>::other entry_allocator;
166 typedef typename entry_allocator::pointer entry_pointer;
167 typedef typename entry_allocator::const_pointer const_entry_pointer;
168 typedef typename entry_allocator::reference entry_reference;
169 typedef typename entry_allocator::const_reference const_entry_reference;
171 typedef typename _Alloc::template rebind<entry_pointer>::other entry_pointer_allocator;
172 typedef typename entry_pointer_allocator::pointer entry_pointer_array;
176 typedef Resize_Policy resize_base;
178 #ifdef _GLIBCXX_DEBUG
179 typedef PB_DS_DEBUG_MAP_BASE_C_DEC debug_base;
182 #define PB_DS_GEN_POS std::pair<entry_pointer, typename _Alloc::size_type>
192 typedef _Alloc allocator_type;
193 typedef typename _Alloc::size_type size_type;
194 typedef typename _Alloc::difference_type difference_type;
195 typedef Hash_Fn hash_fn;
197 typedef Comb_Hash_Fn comb_hash_fn;
198 typedef Resize_Policy resize_policy;
203 store_hash = Store_Hash
206 typedef typename traits_base::key_type key_type;
207 typedef typename traits_base::key_pointer key_pointer;
208 typedef typename traits_base::key_const_pointer key_const_pointer;
209 typedef typename traits_base::key_reference key_reference;
210 typedef typename traits_base::key_const_reference key_const_reference;
211 typedef typename traits_base::mapped_type mapped_type;
212 typedef typename traits_base::mapped_pointer mapped_pointer;
213 typedef typename traits_base::mapped_const_pointer mapped_const_pointer;
214 typedef typename traits_base::mapped_reference mapped_reference;
215 typedef typename traits_base::mapped_const_reference mapped_const_reference;
216 typedef typename traits_base::value_type value_type;
217 typedef typename traits_base::pointer pointer;
218 typedef typename traits_base::const_pointer const_pointer;
219 typedef typename traits_base::reference reference;
220 typedef typename traits_base::const_reference const_reference;
222 #ifdef PB_DS_DATA_TRUE_INDICATOR
223 typedef point_iterator_ point_iterator;
226 #ifdef PB_DS_DATA_FALSE_INDICATOR
227 typedef point_const_iterator_ point_iterator;
230 typedef point_const_iterator_ point_const_iterator;
232 #ifdef PB_DS_DATA_TRUE_INDICATOR
233 typedef iterator_ iterator;
236 #ifdef PB_DS_DATA_FALSE_INDICATOR
237 typedef const_iterator_ iterator;
240 typedef const_iterator_ const_iterator;
242 PB_DS_CC_HASH_NAME();
244 PB_DS_CC_HASH_NAME(
const Hash_Fn&);
246 PB_DS_CC_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&);
248 PB_DS_CC_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Hash_Fn&);
250 PB_DS_CC_HASH_NAME(
const Hash_Fn&,
const Eq_Fn&,
const Comb_Hash_Fn&,
251 const Resize_Policy&);
253 PB_DS_CC_HASH_NAME(
const PB_DS_CLASS_C_DEC&);
256 ~PB_DS_CC_HASH_NAME();
259 swap(PB_DS_CLASS_C_DEC&);
261 template<
typename It>
263 copy_from_range(It, It);
300 get_comb_hash_fn()
const;
308 get_resize_policy()
const;
311 insert(const_reference r_val)
312 {
return insert_imp(r_val, traits_base::m_store_extra_indicator); }
314 inline mapped_reference
317 #ifdef PB_DS_DATA_TRUE_INDICATOR
318 return (subscript_imp(r_key, traits_base::m_store_extra_indicator));
321 return traits_base::s_null_type;
325 inline point_iterator
326 find(key_const_reference);
328 inline point_const_iterator
329 find(key_const_reference)
const;
331 inline point_iterator
334 inline point_const_iterator
338 erase(key_const_reference);
340 template<
typename Pred>
350 inline const_iterator
356 inline const_iterator
359 #ifdef _GLIBCXX_DEBUG
361 assert_valid(
const char*,
int)
const;
364 #ifdef PB_DS_HT_MAP_TRACE_
374 do_resize_if_needed();
377 do_resize_if_needed_no_throw();
380 resize_imp(size_type);
383 do_resize(size_type);
386 resize_imp_no_exceptions(size_type, entry_pointer_array, size_type);
389 resize_imp_no_exceptions_reassign_pointer(entry_pointer,
394 resize_imp_no_exceptions_reassign_pointer(entry_pointer,
399 deallocate_links_in_list(entry_pointer);
402 get_entry(const_reference, false_type);
405 get_entry(const_reference, true_type);
408 rels_entry(entry_pointer);
410 #ifdef PB_DS_DATA_TRUE_INDICATOR
411 inline mapped_reference
412 subscript_imp(key_const_reference r_key, false_type)
414 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
415 const size_type pos = ranged_hash_fn_base::operator()(r_key);
416 entry_pointer p_e = m_entries[pos];
417 resize_base::notify_insert_search_start();
420 && !hash_eq_fn_base::operator()(p_e->m_value.first, r_key))
422 resize_base::notify_insert_search_collision();
426 resize_base::notify_insert_search_end();
429 PB_DS_CHECK_KEY_EXISTS(r_key)
430 return (p_e->m_value.second);
433 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
434 return insert_new_imp(value_type(r_key, mapped_type()), pos)->second;
437 inline mapped_reference
438 subscript_imp(key_const_reference r_key, true_type)
440 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
441 comp_hash pos_hash_pair = ranged_hash_fn_base::operator()(r_key);
442 entry_pointer p_e = m_entries[pos_hash_pair.first];
443 resize_base::notify_insert_search_start();
445 !hash_eq_fn_base::operator()(p_e->m_value.first, p_e->m_hash,
446 r_key, pos_hash_pair.second))
448 resize_base::notify_insert_search_collision();
452 resize_base::notify_insert_search_end();
455 PB_DS_CHECK_KEY_EXISTS(r_key)
456 return p_e->m_value.second;
459 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
460 return insert_new_imp(value_type(r_key, mapped_type()),
461 pos_hash_pair)->second;
466 insert_imp(const_reference, false_type);
469 insert_imp(const_reference, true_type);
472 insert_new_imp(const_reference r_val, size_type pos)
474 if (do_resize_if_needed())
475 pos = ranged_hash_fn_base::operator()(PB_DS_V2F(r_val));
478 entry_pointer p_e = get_entry(r_val,
479 traits_base::m_no_throw_copies_indicator);
482 p_e->m_p_next = m_entries[pos];
483 m_entries[pos] = p_e;
484 resize_base::notify_inserted(++m_num_used_e);
486 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));)
487 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
488 return &p_e->m_value;
492 insert_new_imp(const_reference r_val,
comp_hash& r_pos_hash_pair)
495 if (do_resize_if_needed())
496 r_pos_hash_pair = ranged_hash_fn_base::operator()(PB_DS_V2F(r_val));
498 entry_pointer p_e = get_entry(r_val,
499 traits_base::m_no_throw_copies_indicator);
502 p_e->m_hash = r_pos_hash_pair.
second;
503 p_e->m_p_next = m_entries[r_pos_hash_pair.
first];
504 m_entries[r_pos_hash_pair.
first] = p_e;
505 resize_base::notify_inserted(++m_num_used_e);
506 _GLIBCXX_DEBUG_ONLY(debug_base::insert_new(PB_DS_V2F(r_val));)
507 _GLIBCXX_DEBUG_ONLY(assert_valid(__FILE__, __LINE__);)
508 return &p_e->m_value;
512 find_key_pointer(key_const_reference r_key, false_type)
514 entry_pointer p_e = m_entries[ranged_hash_fn_base::operator()(r_key)];
515 resize_base::notify_find_search_start();
517 !hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value), r_key))
519 resize_base::notify_find_search_collision();
523 resize_base::notify_find_search_end();
525 #ifdef _GLIBCXX_DEBUG
527 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
529 PB_DS_CHECK_KEY_EXISTS(r_key)
531 return &p_e->m_value;
535 find_key_pointer(key_const_reference r_key, true_type)
537 comp_hash pos_hash_pair = ranged_hash_fn_base::operator()(r_key);
538 entry_pointer p_e = m_entries[pos_hash_pair.
first];
539 resize_base::notify_find_search_start();
541 !hash_eq_fn_base::operator()(PB_DS_V2F(p_e->m_value),
543 r_key, pos_hash_pair.
second))
545 resize_base::notify_find_search_collision();
549 resize_base::notify_find_search_end();
551 #ifdef _GLIBCXX_DEBUG
553 PB_DS_CHECK_KEY_DOES_NOT_EXIST(r_key)
555 PB_DS_CHECK_KEY_EXISTS(r_key)
557 return &p_e->m_value;
561 erase_in_pos_imp(key_const_reference, size_type);
564 erase_in_pos_imp(key_const_reference,
const comp_hash&);
567 erase_entry_pointer(entry_pointer&);
569 #ifdef PB_DS_DATA_TRUE_INDICATOR
571 inc_it_state(pointer& r_p_value,
574 inc_it_state((mapped_const_pointer& )r_p_value, r_pos);
579 inc_it_state(const_pointer& r_p_value,
582 _GLIBCXX_DEBUG_ASSERT(r_p_value != 0);
584 if (r_pos.
first != 0)
586 r_p_value = &r_pos.
first->m_value;
591 if (m_entries[r_pos.
second] != 0)
594 r_p_value = &r_pos.
first->m_value;
601 get_start_it_state(pointer& r_p_value,
605 if (m_entries[r_pos.
second] != 0)
608 r_p_value = &r_pos.
first->m_value;
614 #ifdef _GLIBCXX_DEBUG
616 assert_entry_pointer_array_valid(
const entry_pointer_array,
617 const char*,
int)
const;
620 assert_entry_pointer_valid(
const entry_pointer, true_type,
621 const char*,
int)
const;
624 assert_entry_pointer_valid(
const entry_pointer, false_type,
625 const char*,
int)
const;
628 #ifdef PB_DS_HT_MAP_TRACE_
630 trace_list(const_entry_pointer)
const;
634 #ifdef PB_DS_DATA_TRUE_INDICATOR
640 static entry_allocator s_entry_allocator;
641 static entry_pointer_allocator s_entry_pointer_allocator;
642 static iterator s_end_it;
643 static const_iterator s_const_end_it;
644 static point_iterator s_find_end_it;
645 static point_const_iterator s_const_find_end_it;
648 size_type m_num_used_e;
649 entry_pointer_array m_entries;
653 store_hash_ok = !Store_Hash
654 || !is_same<Hash_Fn, __gnu_pbds::null_type>::value
657 PB_DS_STATIC_ASSERT(sth, store_hash_ok);
672 #undef PB_DS_CLASS_T_DEC
673 #undef PB_DS_CLASS_C_DEC
674 #undef PB_DS_HASH_EQ_FN_C_DEC
675 #undef PB_DS_RANGED_HASH_FN_C_DEC
676 #undef PB_DS_CC_HASH_TRAITS_BASE
677 #undef PB_DS_DEBUG_MAP_BASE_C_DEC
678 #undef PB_DS_CC_HASH_NAME
_T1 first
second_type is the second bound type
_T2 second
first is a copy of the first object
Conditional deallocate constructor argument.
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.