3 // Copyright (C) 2005 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file gp_ht_map_.hpp
42 * Contains an implementation class for gp_ht_map_.
45 #include <ext/pb_assoc/detail/cond_dealtor.hpp>
46 #include <ext/pb_assoc/trivial_iterator_def.hpp>
47 #include <ext/pb_assoc/detail/hash_fn/ranged_probe_fn.hpp>
48 #include <ext/pb_assoc/detail/hash_types_traits.hpp>
49 #include <ext/pb_assoc/detail/types_traits.hpp>
50 #include <ext/pb_assoc/exception.hpp>
51 #include <ext/pb_assoc/detail/map_debug_base.hpp>
52 #include <ext/pb_assoc/detail/eq_fn/hash_eq_fn.hpp>
53 #ifdef PB_ASSOC_BASIC_REGRESSION
54 #include <pb_assoc/testsuite/regression/basic_test/throw_prob_adjustor.hpp>
55 #endif // #ifdef PB_ASSOC_BASIC_REGRESSION
64 #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
65 #define PB_ASSOC_DBG_ASSERT(X) assert(X)
66 #define PB_ASSOC_DBG_VERIFY(X) assert(X)
67 #define PB_ASSOC_DBG_ONLY(X) X
68 #else // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
69 #define PB_ASSOC_DBG_ASSERT(X)
70 #define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
71 #define PB_ASSOC_DBG_ONLY(X) ;
72 #endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
74 #define PB_ASSOC_CLASS_T_DEC \
82 class Comb_Probe_Fn, \
86 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
87 #define PB_ASSOC_CLASS_NAME \
89 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
91 #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
92 #define PB_ASSOC_CLASS_NAME \
94 #endif // #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
96 #define PB_ASSOC_CLASS_C_DEC \
97 PB_ASSOC_CLASS_NAME< \
108 #define PB_ASSOC_HASH_EQ_FN_C_DEC \
109 pb_assoc::detail::hash_eq_fn< \
115 #define PB_ASSOC_RANGED_PROBE_FN_C_DEC \
116 pb_assoc::detail::ranged_probe_fn< \
124 #define PB_ASSOC_TYPES_TRAITS_C_DEC \
130 #define PB_ASSOC_HASH_TYPES_TRAITS_C_DEC \
132 typename Allocator::size_type, \
135 #ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
136 #define PB_ASSOC_MAP_DEBUG_BASE_C_DEC \
137 pb_assoc::detail::map_debug_base< \
140 #endif // #ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
142 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
143 #define PB_ASSOC_V2F(X) (X).first
144 #define PB_ASSOC_V2S(X) (X).second
145 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
147 #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
148 #define PB_ASSOC_V2F(X) (X)
149 #define PB_ASSOC_V2S(X) Mapped_Data()
150 #endif // #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
152 #define PB_ASSOC_STATIC_ASSERT(UNIQUE, E) \
154 pb_assoc::detail::static_assert_dummy_class< \
155 sizeof(pb_assoc::detail::static_assert<(bool)(E)>)> \
156 UNIQUE##static_assert_type
158 template<typename Key,
167 class PB_ASSOC_CLASS_NAME :
168 #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
169 protected PB_ASSOC_MAP_DEBUG_BASE_C_DEC,
170 #endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
171 public PB_ASSOC_HASH_EQ_FN_C_DEC,
172 public Resize_Policy,
173 public PB_ASSOC_RANGED_PROBE_FN_C_DEC,
174 public PB_ASSOC_TYPES_TRAITS_C_DEC,
175 public PB_ASSOC_HASH_TYPES_TRAITS_C_DEC
180 typedef typename Allocator::size_type size_type;
183 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_key_reference
186 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::data_type data_type;
189 typename PB_ASSOC_TYPES_TRAITS_C_DEC::data_reference
193 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_data_reference
194 const_data_reference;
196 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::value_type value_type;
198 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::pointer pointer;
201 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_pointer
204 typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::reference reference;
207 typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_reference
212 typedef typename PB_ASSOC_HASH_TYPES_TRAITS_C_DEC::comp_hash comp_hash;
221 typedef char entry_status;
223 struct store_hash_entry
232 struct no_store_hash_entry
243 no_store_hash_entry>::type
247 typename Allocator::template rebind<entry>::other
250 typedef typename entry_allocator::pointer entry_pointer;
252 typedef typename entry_allocator::const_pointer const_entry_pointer;
254 typedef typename entry_allocator::reference entry_reference;
257 typename entry_allocator::const_reference
258 const_entry_reference;
260 typedef typename entry_allocator::pointer entry_array;
262 typedef value_type mapped_value_type;
264 typedef pointer mapped_pointer;
266 typedef const_pointer const_mapped_pointer;
268 typedef reference mapped_reference;
270 typedef const_reference const_mapped_reference;
272 #define PB_ASSOC_GEN_POS size_type
274 #include <ext/pb_assoc/detail/unordered_iterator/const_find_iterator.hpp>
275 #include <ext/pb_assoc/detail/unordered_iterator/find_iterator.hpp>
276 #include <ext/pb_assoc/detail/unordered_iterator/const_iterator.hpp>
277 #include <ext/pb_assoc/detail/unordered_iterator/iterator.hpp>
279 #undef PB_ASSOC_GEN_POS
281 typedef find_iterator_ find_iterator;
283 typedef const_find_iterator_ const_find_iterator;
285 typedef iterator_ iterator;
287 typedef const_iterator_ const_iterator;
289 typedef Hash_Fn hash_fn;
293 typedef Allocator allocator;
295 typedef Probe_Fn probe_fn;
297 typedef Comb_Probe_Fn comb_hash_fn;
299 typedef Resize_Policy resize_policy;
303 PB_ASSOC_CLASS_NAME();
305 PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other);
307 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn);
309 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn);
311 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_probe_fn);
313 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn);
315 PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn, const Resize_Policy& r_resize_policy);
319 copy_from_range(It first_it, It last_it);
322 ~PB_ASSOC_CLASS_NAME();
325 swap(PB_ASSOC_CLASS_C_DEC& r_other);
352 get_probe_fn() const;
358 get_comb_probe_fn() const;
364 get_resize_policy() const;
366 inline std::pair<find_iterator, bool>
367 insert(const_reference r_val);
369 inline data_reference
370 subscript_imp(const_key_reference r_key);
373 find(const_key_reference r_key);
375 inline const_find_iterator
376 find(const_key_reference r_key) const;
381 inline const_find_iterator
385 erase(const_key_reference r_key, int_to_type<false>);
388 erase(const_key_reference r_key, int_to_type<true>);
400 inline const_iterator
406 inline const_iterator
409 #ifdef PB_ASSOC_CC_HT_MAP_DEBUG
412 assert_valid() const;
414 #endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
417 do_resize(size_type new_size);
421 typedef PB_ASSOC_TYPES_TRAITS_C_DEC my_traits_base;
423 typedef PB_ASSOC_HASH_TYPES_TRAITS_C_DEC my_hash_traits_base;
425 typedef PB_ASSOC_RANGED_PROBE_FN_C_DEC my_ranged_probe_fn_base;
427 #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
428 typedef PB_ASSOC_MAP_DEBUG_BASE_C_DEC my_map_debug_base;
429 #endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
431 typedef PB_ASSOC_HASH_EQ_FN_C_DEC my_hash_eq_fn_base;
433 typedef Resize_Policy my_resize_base;
435 friend class iterator_;
437 friend class const_iterator_;
448 constructor_insert_new_imp(const_reference r_val, size_type pos, int_to_type<true>);
451 constructor_insert_new_imp(const_reference r_val, size_type pos, int_to_type<false>);
454 erase_all_valid_entries(entry_array a_entries_resized, size_type size);
457 do_resize_if_needed();
460 do_resize_if_needed_no_throw();
463 resize_imp(entry_array a_entries_resized, size_type old_size);
466 resize_imp_reassign(entry_pointer p_e, entry_array a_entries_resized, int_to_type<false>);
469 resize_imp_reassign(entry_pointer p_e, entry_array a_entries_resized, int_to_type<true>);
472 find_ins_pos(const_key_reference r_key, int_to_type<false>);
475 find_ins_pos(const_key_reference r_key, int_to_type<true>);
477 inline std::pair<find_iterator, bool>
478 insert_imp(const_reference r_val, int_to_type<false>);
480 inline std::pair<find_iterator, bool>
481 insert_imp(const_reference r_val, int_to_type<true>);
484 insert_new_imp(const_reference r_val, size_type pos);
487 insert_new_imp(const_reference r_val, comp_hash& r_pos_hash_pair);
489 inline data_reference
490 subscript_imp(const_key_reference r_key, int_to_type<false>);
492 inline data_reference
493 subscript_imp(const_key_reference r_key, int_to_type<true>);
495 inline const_data_reference
496 const_subscript_imp(const_key_reference r_key) const;
499 find_key_pointer(const_key_reference r_key, int_to_type<false>);
502 find_key_pointer(const_key_reference r_key, int_to_type<true>);
504 inline const_data_reference
505 const_subscript_imp(const_key_reference r_key, int_to_type<false>) const;
507 inline const_data_reference
508 const_subscript_imp(const_key_reference r_key, int_to_type<true>) const;
511 erase_in_pos_imp(const_key_reference r_key, const comp_hash& r_pos_hash_pair);
514 erase_entry(entry_pointer p_e);
516 #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
518 inc_it_state(pointer& r_p_value, size_type& r_pos) const;
519 #endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
522 inc_it_state(const_pointer& r_p_value, size_type& r_pos) const;
525 get_start_it_state(const_pointer& r_p_value, size_type& r_pos) const;
528 get_start_it_state(pointer& r_p_value, size_type& r_pos);
530 #ifdef PB_ASSOC_CC_HT_MAP_DEBUG
533 assert_entry_array_valid(const entry_array a_entries, int_to_type<false>) const;
536 assert_entry_array_valid(const entry_array a_entries, int_to_type<true>) const;
538 #endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
541 static entry_allocator s_entry_allocator;
543 entry_pointer m_a_entries;
547 size_type m_num_used_e;
549 static iterator s_end_it;
551 static const_iterator s_const_end_it;
557 !pb_assoc::detail::is_same_type<
559 pb_assoc::null_hash_fn>::value
562 PB_ASSOC_STATIC_ASSERT(sth, store_hash_ok);
565 #include <ext/pb_assoc/detail/gp_ht_map_/constructor_destructor_fn_imps.hpp>
566 #include <ext/pb_assoc/detail/gp_ht_map_/find_fn_imps.hpp>
567 #include <ext/pb_assoc/detail/gp_ht_map_/resize_fn_imps.hpp>
568 #include <ext/pb_assoc/detail/gp_ht_map_/debug_fn_imps.hpp>
569 #include <ext/pb_assoc/detail/gp_ht_map_/info_fn_imps.hpp>
570 #include <ext/pb_assoc/detail/gp_ht_map_/policy_access_fn_imps.hpp>
571 #include <ext/pb_assoc/detail/gp_ht_map_/erase_fn_imps.hpp>
572 #include <ext/pb_assoc/detail/gp_ht_map_/iterator_fn_imps.hpp>
573 #include <ext/pb_assoc/detail/gp_ht_map_/insert_fn_imps.hpp>
575 #undef PB_ASSOC_CLASS_T_DEC
577 #undef PB_ASSOC_CLASS_C_DEC
579 #undef PB_ASSOC_HASH_EQ_FN_C_DEC
581 #undef PB_ASSOC_RANGED_PROBE_FN_C_DEC
583 #undef PB_ASSOC_TYPES_TRAITS_C_DEC
585 #undef PB_ASSOC_HASH_TYPES_TRAITS_C_DEC
587 #undef PB_ASSOC_MAP_DEBUG_BASE_C_DEC
589 #undef PB_ASSOC_CLASS_NAME
594 #undef PB_ASSOC_DBG_ASSERT
595 #undef PB_ASSOC_DBG_VERIFY
596 #undef PB_ASSOC_DBG_ONLY
598 #undef PB_ASSOC_STATIC_ASSERT
600 } // namespace detail
602 } // namespace pb_assoc