14 #ifndef EASTL_HASH_MAP_H
15 #define EASTL_HASH_MAP_H
18 #include <EASTL/internal/config.h>
19 #include <EASTL/internal/hashtable.h>
20 #include <EASTL/functional.h>
21 #include <EASTL/utility.h>
23 #if defined(EA_PRAGMA_ONCE_SUPPORTED)
36 #ifndef EASTL_HASH_MAP_DEFAULT_NAME
37 #define EASTL_HASH_MAP_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " hash_map"
45 #ifndef EASTL_HASH_MULTIMAP_DEFAULT_NAME
46 #define EASTL_HASH_MULTIMAP_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " hash_multimap"
52 #ifndef EASTL_HASH_MAP_DEFAULT_ALLOCATOR
53 #define EASTL_HASH_MAP_DEFAULT_ALLOCATOR allocator_type(EASTL_HASH_MAP_DEFAULT_NAME)
58 #ifndef EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR
59 #define EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR allocator_type(EASTL_HASH_MULTIMAP_DEFAULT_NAME)
99 template <
typename Key,
typename T,
typename Hash = eastl::hash<Key>,
typename Predicate = eastl::equal_to<Key>,
100 typename Allocator = EASTLAllocatorType,
bool bCacheHashCode = false>
102 :
public hashtable<Key, eastl::pair<const Key, T>, Allocator, eastl::use_first<eastl::pair<const Key, T> >, Predicate,
103 Hash, mod_range_hashing, default_ranged_hash, prime_rehash_policy, bCacheHashCode, true, true>
111 typedef typename base_type::size_type size_type;
112 typedef typename base_type::key_type key_type;
113 typedef T mapped_type;
114 typedef typename base_type::value_type value_type;
115 typedef typename base_type::allocator_type allocator_type;
121 using base_type::insert;
142 explicit hash_map(size_type nBucketCount,
const Hash& hashFunction = Hash(),
143 const Predicate& predicate = Predicate(),
const allocator_type&
allocator = EASTL_HASH_MAP_DEFAULT_ALLOCATOR)
163 hash_map(this_type&& x,
const allocator_type& allocator)
175 const Predicate& predicate = Predicate(),
const allocator_type&
allocator = EASTL_HASH_MAP_DEFAULT_ALLOCATOR)
188 template <
typename ForwardIterator>
189 hash_map(ForwardIterator first, ForwardIterator last, size_type nBucketCount = 0,
const Hash& hashFunction = Hash(),
190 const Predicate& predicate = Predicate(),
const allocator_type&
allocator = EASTL_HASH_MAP_DEFAULT_ALLOCATOR)
198 this_type& operator=(
const this_type& x)
200 return static_cast<this_type&
>(base_type::operator=(x));
206 return static_cast<this_type&
>(base_type::operator=(ilist));
210 this_type& operator=(this_type&& x)
212 return static_cast<this_type&
>(base_type::operator=(
eastl::move(x)));
224 return base_type::DoInsertKey(
true_type(), key);
227 T& at(
const key_type& k)
231 if (it == base_type::end())
233 #if EASTL_EXCEPTIONS_ENABLED
235 throw std::out_of_range(
"invalid hash_map<K, T> key");
238 EASTL_ASSERT_MSG(
false,
"invalid hash_map<K, T> key");
246 const T& at(
const key_type& k)
const
248 const_iterator it = base_type::find(k);
250 if (it == base_type::end())
252 #if EASTL_EXCEPTIONS_ENABLED
254 throw std::out_of_range(
"invalid hash_map<K, T> key");
257 EASTL_ASSERT_MSG(
false,
"invalid hash_map<K, T> key");
265 insert_return_type
insert(key_type&& key)
267 return base_type::DoInsertKey(true_type(),
eastl::move(key));
271 mapped_type& operator[](
const key_type& key)
273 return (*base_type::DoInsertKey(true_type(), key).first).second;
282 mapped_type& operator[](key_type&& key)
285 return (*base_type::DoInsertKey(true_type(),
eastl::move(key)).first).second;
294 template <
typename Key,
typename T,
typename Hash,
typename Predicate,
typename Allocator,
bool bCacheHashCode,
typename UserPredicate>
298 for (
auto i = c.begin(), last = c.end(); i != last;)
318 template <
typename Key,
typename T,
typename Hash = eastl::hash<Key>,
typename Predicate = eastl::equal_to<Key>,
319 typename Allocator = EASTLAllocatorType,
bool bCacheHashCode = false>
321 :
public hashtable<Key, eastl::pair<const Key, T>, Allocator, eastl::use_first<eastl::pair<const Key, T> >, Predicate,
322 Hash, mod_range_hashing, default_ranged_hash, prime_rehash_policy, bCacheHashCode, true, false>
330 typedef typename base_type::size_type size_type;
331 typedef typename base_type::key_type key_type;
332 typedef T mapped_type;
333 typedef typename base_type::value_type value_type;
334 typedef typename base_type::allocator_type allocator_type;
339 using base_type::insert;
342 using base_type::try_emplace;
343 using base_type::insert_or_assign;
364 explicit hash_multimap(size_type nBucketCount,
const Hash& hashFunction = Hash(),
365 const Predicate& predicate = Predicate(),
const allocator_type&
allocator = EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR)
385 hash_multimap(this_type&& x,
const allocator_type& allocator)
397 const Predicate& predicate = Predicate(),
const allocator_type&
allocator = EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR)
410 template <
typename ForwardIterator>
411 hash_multimap(ForwardIterator first, ForwardIterator last, size_type nBucketCount = 0,
const Hash& hashFunction = Hash(),
412 const Predicate& predicate = Predicate(),
const allocator_type&
allocator = EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR)
420 this_type& operator=(
const this_type& x)
422 return static_cast<this_type&
>(base_type::operator=(x));
428 return static_cast<this_type&
>(base_type::operator=(ilist));
432 this_type& operator=(this_type&& x)
434 return static_cast<this_type&
>(base_type::operator=(
eastl::move(x)));
446 return base_type::DoInsertKey(
false_type(), key);
450 insert_return_type insert(key_type&& key)
460 template <
typename Key,
typename T,
typename Hash,
typename Predicate,
typename Allocator,
bool bCacheHashCode,
typename UserPredicate>
464 for (
auto i = c.begin(), last = c.end(); i != last;)
483 template <
typename Key,
typename T,
typename Hash,
typename Predicate,
typename Allocator,
bool bCacheHashCode>
484 inline bool operator==(
const hash_map<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& a,
485 const hash_map<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& b)
487 typedef typename hash_map<Key, T, Hash, Predicate, Allocator, bCacheHashCode>::const_iterator const_iterator;
490 if(a.size() != b.size())
495 for(const_iterator ai = a.begin(), aiEnd = a.end(), biEnd = b.end(); ai != aiEnd; ++ai)
497 const_iterator bi = b.find(ai->first);
499 if((bi == biEnd) || !(*ai == *bi))
506 template <
typename Key,
typename T,
typename Hash,
typename Predicate,
typename Allocator,
bool bCacheHashCode>
507 inline bool operator!=(
const hash_map<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& a,
508 const hash_map<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& b)
514 template <
typename Key,
typename T,
typename Hash,
typename Predicate,
typename Allocator,
bool bCacheHashCode>
515 inline bool operator==(
const hash_multimap<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& a,
516 const hash_multimap<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& b)
518 typedef typename hash_multimap<Key, T, Hash, Predicate, Allocator, bCacheHashCode>::const_iterator const_iterator;
519 typedef typename eastl::iterator_traits<const_iterator>::difference_type difference_type;
522 if(a.size() != b.size())
532 for(const_iterator ai = a.begin(), aiEnd = a.end(); ai != aiEnd; ai = aRange.second)
534 aRange = a.equal_range(ai->first);
535 bRange = b.equal_range(ai->first);
538 const difference_type aDistance = eastl::distance(aRange.first, aRange.second);
539 const difference_type bDistance = eastl::distance(bRange.first, bRange.second);
541 if(aDistance != bDistance)
548 if(!(*aRange.first == *bRange.first))
563 template <
typename Key,
typename T,
typename Hash,
typename Predicate,
typename Allocator,
bool bCacheHashCode>
564 inline bool operator!=(
const hash_multimap<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& a,
565 const hash_multimap<Key, T, Hash, Predicate, Allocator, bCacheHashCode>& b)
Definition: allocator.h:52
Definition: hash_map.h:104
hash_map(ForwardIterator first, ForwardIterator last, size_type nBucketCount=0, const Hash &hashFunction=Hash(), const Predicate &predicate=Predicate(), const allocator_type &allocator=EASTL_HASH_MAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:189
hash_map(const allocator_type &allocator=EASTL_HASH_MAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:128
hash_map(size_type nBucketCount, const Hash &hashFunction=Hash(), const Predicate &predicate=Predicate(), const allocator_type &allocator=EASTL_HASH_MAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:142
insert_return_type insert(const key_type &key)
Definition: hash_map.h:222
hash_map(std::initializer_list< value_type > ilist, size_type nBucketCount=0, const Hash &hashFunction=Hash(), const Predicate &predicate=Predicate(), const allocator_type &allocator=EASTL_HASH_MAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:174
Definition: hash_map.h:323
hash_multimap(const allocator_type &allocator=EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:350
hash_multimap(size_type nBucketCount, const Hash &hashFunction=Hash(), const Predicate &predicate=Predicate(), const allocator_type &allocator=EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:364
hash_multimap(ForwardIterator first, ForwardIterator last, size_type nBucketCount=0, const Hash &hashFunction=Hash(), const Predicate &predicate=Predicate(), const allocator_type &allocator=EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:411
insert_return_type insert(const key_type &key)
Definition: hash_map.h:444
hash_multimap(std::initializer_list< value_type > ilist, size_type nBucketCount=0, const Hash &hashFunction=Hash(), const Predicate &predicate=Predicate(), const allocator_type &allocator=EASTL_HASH_MULTIMAP_DEFAULT_ALLOCATOR)
Definition: hash_map.h:396
Definition: hashtable.h:830
Definition: initializer_list.h:38
EA Standard Template Library.
Definition: algorithm.h:288
OutputIterator move(InputIterator first, InputIterator last, OutputIterator result)
Definition: copy_help.h:170
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2)
Definition: algorithm.h:3749
Definition: hashtable.h:406
Definition: hashtable.h:107
Definition: hashtable.h:311
Definition: type_traits.h:263
Definition: iterator.h:86
Definition: hashtable.h:392
Definition: utility.h:371
Definition: hashtable.h:415
Definition: red_black_tree.h:152
Definition: utility.h:596