IOSS  2.0
robin_map.h
Go to the documentation of this file.
1 /**
2  * MIT License
3  *
4  * Copyright (c) 2017 Tessil
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef TSL_ROBIN_MAP_H
25 #define TSL_ROBIN_MAP_H
26 
27 #include "robin_hash.h"
28 #include <cstddef>
29 #include <functional>
30 #include <initializer_list>
31 #include <memory>
32 #include <type_traits>
33 #include <utility>
34 
35 namespace tsl {
36 
37  /**
38  * Implementation of a hash map using open-adressing and the robin hood hashing algorithm with
39  * backward shift deletion.
40  *
41  * For operations modifying the hash map (insert, erase, rehash, ...), the strong exception
42  * guarantee is only guaranteed when the expression `std::is_nothrow_swappable<std::pair<Key,
43  * T>>\:\:value && std::is_nothrow_move_constructible<std::pair<Key, T>>\:\:value` is true,
44  * otherwise if an exception is thrown during the swap or the move, the hash map may end up in a
45  * undefined state. Per the standard a `Key` or `T` with a noexcept copy constructor and no move
46  * constructor also satisfies the `std::is_nothrow_move_constructible<std::pair<Key, T>>\:\:value`
47  * criterion (and will thus guarantee the strong exception for the map).
48  *
49  * When `StoreHash` is true, 32 bits of the hash are stored alongside the values. It can improve
50  * the performance during lookups if the `KeyEqual` function takes time (if it engenders a
51  * cache-miss for example) as we then compare the stored hashes before comparing the keys. When
52  * `tsl::rh::power_of_two_growth_policy` is used as `GrowthPolicy`, it may also speed-up the
53  * rehash process as we can avoid to recalculate the hash. When it is detected that storing the
54  * hash will not incur any memory penalty due to alignment (i.e.
55  * `sizeof(tsl::detail_robin_hash::bucket_entry<ValueType, true>) ==
56  * sizeof(tsl::detail_robin_hash::bucket_entry<ValueType, false>)`) and
57  * `tsl::rh::power_of_two_growth_policy` is used, the hash will be stored even if `StoreHash` is
58  * false so that we can speed-up the rehash (but it will not be used on lookups unless `StoreHash`
59  * is true).
60  *
61  * `GrowthPolicy` defines how the map grows and consequently how a hash value is mapped to a
62  * bucket. By default the map uses `tsl::rh::power_of_two_growth_policy`. This policy keeps the
63  * number of buckets to a power of two and uses a mask to map the hash to a bucket instead of the
64  * slow modulo. Other growth policies are available and you may define your own growth policy,
65  * check `tsl::rh::power_of_two_growth_policy` for the interface.
66  *
67  * `std::pair<Key, T>` must be swappable.
68  *
69  * `Key` and `T` must be copy and/or move constructible.
70  *
71  * If the destructor of `Key` or `T` throws an exception, the behaviour of the class is undefined.
72  *
73  * Iterators invalidation:
74  * - clear, operator=, reserve, rehash: always invalidate the iterators.
75  * - insert, emplace, emplace_hint, operator[]: if there is an effective insert, invalidate the
76  * iterators.
77  * - erase: always invalidate the iterators.
78  */
79  template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
80  class Allocator = std::allocator<std::pair<Key, T>>, bool StoreHash = false,
81  class GrowthPolicy = tsl::rh::power_of_two_growth_policy<2>>
82  class robin_map
83  {
84  private:
86 
87  class KeySelect
88  {
89  public:
90  using key_type = Key;
91 
92  const key_type &operator()(const std::pair<Key, T> &key_value) const noexcept
93  {
94  return key_value.first;
95  }
96 
97  key_type &operator()(std::pair<Key, T> &key_value) noexcept { return key_value.first; }
98  };
99 
101  {
102  public:
103  using value_type = T;
104 
105  const value_type &operator()(const std::pair<Key, T> &key_value) const noexcept
106  {
107  return key_value.second;
108  }
109 
110  value_type &operator()(std::pair<Key, T> &key_value) noexcept { return key_value.second; }
111  };
112 
113  using ht = detail_robin_hash::robin_hash<std::pair<Key, T>, KeySelect, ValueSelect, Hash,
114  KeyEqual, Allocator, StoreHash, GrowthPolicy>;
115 
116  public:
117  using key_type = typename ht::key_type;
118  using mapped_type = T;
119  using value_type = typename ht::value_type;
120  using size_type = typename ht::size_type;
122  using hasher = typename ht::hasher;
123  using key_equal = typename ht::key_equal;
125  using reference = typename ht::reference;
127  using pointer = typename ht::pointer;
129  using iterator = typename ht::iterator;
131 
132  public:
133  /*
134  * Constructors
135  */
136  robin_map() : robin_map(ht::DEFAULT_INIT_BUCKETS_SIZE) {}
137 
138  explicit robin_map(size_type bucket_count, const Hash &hash = Hash(),
139  const KeyEqual &equal = KeyEqual(), const Allocator &alloc = Allocator())
140  : m_ht(bucket_count, hash, equal, alloc)
141  {
142  }
143 
144  robin_map(size_type bucket_count, const Allocator &alloc)
145  : robin_map(bucket_count, Hash(), KeyEqual(), alloc)
146  {
147  }
148 
149  robin_map(size_type bucket_count, const Hash &hash, const Allocator &alloc)
150  : robin_map(bucket_count, hash, KeyEqual(), alloc)
151  {
152  }
153 
154  explicit robin_map(const Allocator &alloc) : robin_map(ht::DEFAULT_INIT_BUCKETS_SIZE, alloc) {}
155 
156  template <class InputIt>
158  const Hash &hash = Hash(), const KeyEqual &equal = KeyEqual(),
159  const Allocator &alloc = Allocator())
160  : robin_map(bucket_count, hash, equal, alloc)
161  {
162  insert(first, last);
163  }
164 
165  template <class InputIt>
166  robin_map(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
167  : robin_map(first, last, bucket_count, Hash(), KeyEqual(), alloc)
168  {
169  }
170 
171  template <class InputIt>
172  robin_map(InputIt first, InputIt last, size_type bucket_count, const Hash &hash,
173  const Allocator &alloc)
174  : robin_map(first, last, bucket_count, hash, KeyEqual(), alloc)
175  {
176  }
177 
178  robin_map(std::initializer_list<value_type> init,
179  size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash = Hash(),
180  const KeyEqual &equal = KeyEqual(), const Allocator &alloc = Allocator())
181  : robin_map(init.begin(), init.end(), bucket_count, hash, equal, alloc)
182  {
183  }
184 
185  robin_map(std::initializer_list<value_type> init, size_type bucket_count,
186  const Allocator &alloc)
187  : robin_map(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
188  {
189  }
190 
191  robin_map(std::initializer_list<value_type> init, size_type bucket_count, const Hash &hash,
192  const Allocator &alloc)
193  : robin_map(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
194  {
195  }
196 
197  robin_map &operator=(std::initializer_list<value_type> ilist)
198  {
199  m_ht.clear();
200 
201  m_ht.reserve(ilist.size());
202  m_ht.insert(ilist.begin(), ilist.end());
203 
204  return *this;
205  }
206 
208 
209  /*
210  * Iterators
211  */
212  iterator begin() noexcept { return m_ht.begin(); }
213  const_iterator begin() const noexcept { return m_ht.begin(); }
214  const_iterator cbegin() const noexcept { return m_ht.cbegin(); }
215 
216  iterator end() noexcept { return m_ht.end(); }
217  const_iterator end() const noexcept { return m_ht.end(); }
218  const_iterator cend() const noexcept { return m_ht.cend(); }
219 
220  /*
221  * Capacity
222  */
223  bool empty() const noexcept { return m_ht.empty(); }
224  size_type size() const noexcept { return m_ht.size(); }
225  size_type max_size() const noexcept { return m_ht.max_size(); }
226 
227  /*
228  * Modifiers
229  */
230  void clear() noexcept { m_ht.clear(); }
231 
232  std::pair<iterator, bool> insert(const value_type &value) { return m_ht.insert(value); }
233 
234  template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
235  * = nullptr>
236  std::pair<iterator, bool> insert(P &&value)
237  {
238  return m_ht.emplace(std::forward<P>(value));
239  }
240 
241  std::pair<iterator, bool> insert(value_type &&value) { return m_ht.insert(std::move(value)); }
242 
244  {
245  return m_ht.insert_hint(hint, value);
246  }
247 
248  template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
249  * = nullptr>
250  iterator insert(const_iterator hint, P &&value)
251  {
252  return m_ht.emplace_hint(hint, std::forward<P>(value));
253  }
254 
256  {
257  return m_ht.insert_hint(hint, std::move(value));
258  }
259 
260  template <class InputIt> void insert(InputIt first, InputIt last) { m_ht.insert(first, last); }
261 
262  void insert(std::initializer_list<value_type> ilist)
263  {
264  m_ht.insert(ilist.begin(), ilist.end());
265  }
266 
267  template <class M> std::pair<iterator, bool> insert_or_assign(const key_type &k, M &&obj)
268  {
269  return m_ht.insert_or_assign(k, std::forward<M>(obj));
270  }
271 
272  template <class M> std::pair<iterator, bool> insert_or_assign(key_type &&k, M &&obj)
273  {
274  return m_ht.insert_or_assign(std::move(k), std::forward<M>(obj));
275  }
276 
277  template <class M> iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
278  {
279  return m_ht.insert_or_assign(hint, k, std::forward<M>(obj));
280  }
281 
282  template <class M> iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
283  {
284  return m_ht.insert_or_assign(hint, std::move(k), std::forward<M>(obj));
285  }
286 
287  /**
288  * Due to the way elements are stored, emplace will need to move or copy the key-value once.
289  * The method is equivalent to insert(value_type(std::forward<Args>(args)...));
290  *
291  * Mainly here for compatibility with the std::unordered_map interface.
292  */
293  template <class... Args> std::pair<iterator, bool> emplace(Args &&... args)
294  {
295  return m_ht.emplace(std::forward<Args>(args)...);
296  }
297 
298  /**
299  * Due to the way elements are stored, emplace_hint will need to move or copy the key-value
300  * once. The method is equivalent to insert(hint, value_type(std::forward<Args>(args)...));
301  *
302  * Mainly here for compatibility with the std::unordered_map interface.
303  */
304  template <class... Args> iterator emplace_hint(const_iterator hint, Args &&... args)
305  {
306  return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
307  }
308 
309  template <class... Args>
310  std::pair<iterator, bool> try_emplace(const key_type &k, Args &&... args)
311  {
312  return m_ht.try_emplace(k, std::forward<Args>(args)...);
313  }
314 
315  template <class... Args> std::pair<iterator, bool> try_emplace(key_type &&k, Args &&... args)
316  {
317  return m_ht.try_emplace(std::move(k), std::forward<Args>(args)...);
318  }
319 
320  template <class... Args>
321  iterator try_emplace(const_iterator hint, const key_type &k, Args &&... args)
322  {
323  return m_ht.try_emplace_hint(hint, k, std::forward<Args>(args)...);
324  }
325 
326  template <class... Args>
327  iterator try_emplace(const_iterator hint, key_type &&k, Args &&... args)
328  {
329  return m_ht.try_emplace_hint(hint, std::move(k), std::forward<Args>(args)...);
330  }
331 
332  iterator erase(iterator pos) { return m_ht.erase(pos); }
333  iterator erase(const_iterator pos) { return m_ht.erase(pos); }
334  iterator erase(const_iterator first, const_iterator last) { return m_ht.erase(first, last); }
335  size_type erase(const key_type &key) { return m_ht.erase(key); }
336 
337  /**
338  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
339  * the same as hash_function()(key). Useful to speed-up the lookup to the value if you already
340  * have the hash.
341  */
342  size_type erase(const key_type &key, std::size_t precalculated_hash)
343  {
344  return m_ht.erase(key, precalculated_hash);
345  }
346 
347  /**
348  * This overload only participates in the overload resolution if the typedef
349  * KeyEqual::is_transparent exists. If so, K must be hashable and comparable to Key.
350  */
351  template <class K, class KE = KeyEqual,
352  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
353  size_type erase(const K &key)
354  {
355  return m_ht.erase(key);
356  }
357 
358  /**
359  * @copydoc erase(const K& key)
360  *
361  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
362  * the same as hash_function()(key). Useful to speed-up the lookup to the value if you already
363  * have the hash.
364  */
365  template <class K, class KE = KeyEqual,
366  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
367  size_type erase(const K &key, std::size_t precalculated_hash)
368  {
369  return m_ht.erase(key, precalculated_hash);
370  }
371 
372  void swap(robin_map &other) { other.m_ht.swap(m_ht); }
373 
374  /*
375  * Lookup
376  */
377  T &at(const Key &key) { return m_ht.at(key); }
378 
379  /**
380  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
381  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
382  * hash.
383  */
384  T &at(const Key &key, std::size_t precalculated_hash)
385  {
386  return m_ht.at(key, precalculated_hash);
387  }
388 
389  const T &at(const Key &key) const { return m_ht.at(key); }
390 
391  /**
392  * @copydoc at(const Key& key, std::size_t precalculated_hash)
393  */
394  const T &at(const Key &key, std::size_t precalculated_hash) const
395  {
396  return m_ht.at(key, precalculated_hash);
397  }
398 
399  /**
400  * This overload only participates in the overload resolution if the typedef
401  * KeyEqual::is_transparent exists. If so, K must be hashable and comparable to Key.
402  */
403  template <class K, class KE = KeyEqual,
404  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
405  T &at(const K &key)
406  {
407  return m_ht.at(key);
408  }
409 
410  /**
411  * @copydoc at(const K& key)
412  *
413  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
414  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
415  * hash.
416  */
417  template <class K, class KE = KeyEqual,
418  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
419  T &at(const K &key, std::size_t precalculated_hash)
420  {
421  return m_ht.at(key, precalculated_hash);
422  }
423 
424  /**
425  * @copydoc at(const K& key)
426  */
427  template <class K, class KE = KeyEqual,
428  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
429  const T &at(const K &key) const
430  {
431  return m_ht.at(key);
432  }
433 
434  /**
435  * @copydoc at(const K& key, std::size_t precalculated_hash)
436  */
437  template <class K, class KE = KeyEqual,
438  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
439  const T &at(const K &key, std::size_t precalculated_hash) const
440  {
441  return m_ht.at(key, precalculated_hash);
442  }
443 
444  T &operator[](const Key &key) { return m_ht[key]; }
445  T &operator[](Key &&key) { return m_ht[std::move(key)]; }
446 
447  size_type count(const Key &key) const { return m_ht.count(key); }
448 
449  /**
450  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
451  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
452  * hash.
453  */
454  size_type count(const Key &key, std::size_t precalculated_hash) const
455  {
456  return m_ht.count(key, precalculated_hash);
457  }
458 
459  /**
460  * This overload only participates in the overload resolution if the typedef
461  * KeyEqual::is_transparent exists. If so, K must be hashable and comparable to Key.
462  */
463  template <class K, class KE = KeyEqual,
464  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
465  size_type count(const K &key) const
466  {
467  return m_ht.count(key);
468  }
469 
470  /**
471  * @copydoc count(const K& key) const
472  *
473  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
474  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
475  * hash.
476  */
477  template <class K, class KE = KeyEqual,
478  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
479  size_type count(const K &key, std::size_t precalculated_hash) const
480  {
481  return m_ht.count(key, precalculated_hash);
482  }
483 
484  iterator find(const Key &key) { return m_ht.find(key); }
485 
486  /**
487  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
488  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
489  * hash.
490  */
491  iterator find(const Key &key, std::size_t precalculated_hash)
492  {
493  return m_ht.find(key, precalculated_hash);
494  }
495 
496  const_iterator find(const Key &key) const { return m_ht.find(key); }
497 
498  /**
499  * @copydoc find(const Key& key, std::size_t precalculated_hash)
500  */
501  const_iterator find(const Key &key, std::size_t precalculated_hash) const
502  {
503  return m_ht.find(key, precalculated_hash);
504  }
505 
506  /**
507  * This overload only participates in the overload resolution if the typedef
508  * KeyEqual::is_transparent exists. If so, K must be hashable and comparable to Key.
509  */
510  template <class K, class KE = KeyEqual,
511  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
512  iterator find(const K &key)
513  {
514  return m_ht.find(key);
515  }
516 
517  /**
518  * @copydoc find(const K& key)
519  *
520  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
521  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
522  * hash.
523  */
524  template <class K, class KE = KeyEqual,
525  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
526  iterator find(const K &key, std::size_t precalculated_hash)
527  {
528  return m_ht.find(key, precalculated_hash);
529  }
530 
531  /**
532  * @copydoc find(const K& key)
533  */
534  template <class K, class KE = KeyEqual,
535  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
536  const_iterator find(const K &key) const
537  {
538  return m_ht.find(key);
539  }
540 
541  /**
542  * @copydoc find(const K& key)
543  *
544  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
545  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
546  * hash.
547  */
548  template <class K, class KE = KeyEqual,
549  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
550  const_iterator find(const K &key, std::size_t precalculated_hash) const
551  {
552  return m_ht.find(key, precalculated_hash);
553  }
554 
555  std::pair<iterator, iterator> equal_range(const Key &key) { return m_ht.equal_range(key); }
556 
557  /**
558  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
559  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
560  * hash.
561  */
562  std::pair<iterator, iterator> equal_range(const Key &key, std::size_t precalculated_hash)
563  {
564  return m_ht.equal_range(key, precalculated_hash);
565  }
566 
567  std::pair<const_iterator, const_iterator> equal_range(const Key &key) const
568  {
569  return m_ht.equal_range(key);
570  }
571 
572  /**
573  * @copydoc equal_range(const Key& key, std::size_t precalculated_hash)
574  */
575  std::pair<const_iterator, const_iterator> equal_range(const Key & key,
576  std::size_t precalculated_hash) const
577  {
578  return m_ht.equal_range(key, precalculated_hash);
579  }
580 
581  /**
582  * This overload only participates in the overload resolution if the typedef
583  * KeyEqual::is_transparent exists. If so, K must be hashable and comparable to Key.
584  */
585  template <class K, class KE = KeyEqual,
586  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
587  std::pair<iterator, iterator> equal_range(const K &key)
588  {
589  return m_ht.equal_range(key);
590  }
591 
592  /**
593  * @copydoc equal_range(const K& key)
594  *
595  * Use the hash value 'precalculated_hash' instead of hashing the key. The hash value should be
596  * the same as hash_function()(key). Useful to speed-up the lookup if you already have the
597  * hash.
598  */
599  template <class K, class KE = KeyEqual,
600  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
601  std::pair<iterator, iterator> equal_range(const K &key, std::size_t precalculated_hash)
602  {
603  return m_ht.equal_range(key, precalculated_hash);
604  }
605 
606  /**
607  * @copydoc equal_range(const K& key)
608  */
609  template <class K, class KE = KeyEqual,
610  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
611  std::pair<const_iterator, const_iterator> equal_range(const K &key) const
612  {
613  return m_ht.equal_range(key);
614  }
615 
616  /**
617  * @copydoc equal_range(const K& key, std::size_t precalculated_hash)
618  */
619  template <class K, class KE = KeyEqual,
620  typename std::enable_if<has_is_transparent<KE>::value>::type * = nullptr>
621  std::pair<const_iterator, const_iterator> equal_range(const K & key,
622  std::size_t precalculated_hash) const
623  {
624  return m_ht.equal_range(key, precalculated_hash);
625  }
626 
627  /*
628  * Bucket interface
629  */
630  size_type bucket_count() const { return m_ht.bucket_count(); }
632 
633  /*
634  * Hash policy
635  */
636  float load_factor() const { return m_ht.load_factor(); }
637 
638  float min_load_factor() const { return m_ht.min_load_factor(); }
639  float max_load_factor() const { return m_ht.max_load_factor(); }
640 
641  /**
642  * Set the `min_load_factor` to `ml`. When the `load_factor` of the map goes
643  * below `min_load_factor` after some erase operations, the map will be
644  * shrunk when an insertion occurs. The erase method itself never shrinks
645  * the map.
646  *
647  * The default value of `min_load_factor` is 0.0f, the map never shrinks by default.
648  */
649  void min_load_factor(float ml) { m_ht.min_load_factor(ml); }
650  void max_load_factor(float ml) { m_ht.max_load_factor(ml); }
651 
652  void rehash(size_type my_count) { m_ht.rehash(my_count); }
653  void reserve(size_type my_count) { m_ht.reserve(my_count); }
654 
655  /*
656  * Observers
657  */
658  hasher hash_function() const { return m_ht.hash_function(); }
659  key_equal key_eq() const { return m_ht.key_eq(); }
660 
661  /*
662  * Other
663  */
664 
665  /**
666  * Convert a const_iterator to an iterator.
667  */
669 
670  friend bool operator==(const robin_map &lhs, const robin_map &rhs)
671  {
672  if (lhs.size() != rhs.size()) {
673  return false;
674  }
675 
676  for (const auto &element_lhs : lhs) {
677  const auto it_element_rhs = rhs.find(element_lhs.first);
678  if (it_element_rhs == rhs.cend() || element_lhs.second != it_element_rhs->second) {
679  return false;
680  }
681  }
682 
683  return true;
684  }
685 
686  friend bool operator!=(const robin_map &lhs, const robin_map &rhs)
687  {
688  return !operator==(lhs, rhs);
689  }
690 
691  friend void swap(robin_map &lhs, robin_map &rhs) { lhs.swap(rhs); }
692 
693  private:
695  };
696 
697  /**
698  * Same as `tsl::robin_map<Key, T, Hash, KeyEqual, Allocator, StoreHash,
699  * tsl::rh::prime_growth_policy>`.
700  */
701  template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
702  class Allocator = std::allocator<std::pair<Key, T>>, bool StoreHash = false>
703  using robin_pg_map =
705 
706 } // end namespace tsl
707 
708 #endif
tsl::robin_map::mutable_iterator
iterator mutable_iterator(const_iterator pos)
Definition: robin_map.h:668
tsl::robin_map::min_load_factor
float min_load_factor() const
Definition: robin_map.h:638
tsl
Definition: bhopscotch_map.h:37
tsl::robin_map< cgsize_t, cgsize_t >::const_reference
typename ht::const_reference const_reference
Definition: robin_map.h:126
tsl::robin_map::emplace
std::pair< iterator, bool > emplace(Args &&... args)
Definition: robin_map.h:293
tsl::robin_map::find
iterator find(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:526
tsl::robin_map::at
const T & at(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:439
tsl::robin_map::equal_range
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: robin_map.h:567
tsl::detail_robin_hash::robin_hash::hash_function
hasher hash_function() const
Definition: robin_hash.h:1034
tsl::detail_robin_hash::robin_hash::size
size_type size() const noexcept
Definition: robin_hash.h:669
tsl::robin_map::ValueSelect
Definition: robin_map.h:100
tsl::detail_robin_hash::robin_hash::max_load_factor
float max_load_factor() const
Definition: robin_hash.h:1005
tsl::robin_map::insert
std::pair< iterator, bool > insert(P &&value)
Definition: robin_map.h:236
tsl::robin_map::robin_map
robin_map(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: robin_map.h:138
tsl::robin_map::operator[]
T & operator[](const Key &key)
Definition: robin_map.h:444
tsl::robin_map::max_bucket_count
size_type max_bucket_count() const
Definition: robin_map.h:631
tsl::robin_map::find
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: robin_map.h:491
tsl::robin_map< cgsize_t, cgsize_t >::key_equal
typename ht::key_equal key_equal
Definition: robin_map.h:123
tsl::detail_robin_hash::robin_hash::emplace
std::pair< iterator, bool > emplace(Args &&... args)
Definition: robin_hash.h:740
tsl::robin_map::at
const T & at(const K &key) const
Definition: robin_map.h:429
tsl::robin_map::end
iterator end() noexcept
Definition: robin_map.h:216
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::pointer
value_type * pointer
Definition: robin_hash.h:348
tsl::robin_map::hash_function
hasher hash_function() const
Definition: robin_map.h:658
tsl::robin_map::erase
iterator erase(const_iterator first, const_iterator last)
Definition: robin_map.h:334
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::difference_type
std::ptrdiff_t difference_type
Definition: robin_hash.h:342
tsl::robin_map::equal_range
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: robin_map.h:562
tsl::robin_map::begin
iterator begin() noexcept
Definition: robin_map.h:212
anonymous_namespace{Ioss_SmartAssert.C}::init
struct anonymous_namespace{Ioss_SmartAssert.C}::assert_initializer init
tsl::robin_map::at
T & at(const K &key)
Definition: robin_map.h:405
tsl::robin_map::swap
void swap(robin_map &other)
Definition: robin_map.h:372
tsl::robin_map::ValueSelect::operator()
value_type & operator()(std::pair< Key, T > &key_value) noexcept
Definition: robin_map.h:110
tsl::robin_map::end
const_iterator end() const noexcept
Definition: robin_map.h:217
tsl::detail_robin_hash::robin_hash::empty
bool empty() const noexcept
Definition: robin_hash.h:667
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::size_type
std::size_t size_type
Definition: robin_hash.h:341
tsl::robin_map::insert
iterator insert(const_iterator hint, value_type &&value)
Definition: robin_map.h:255
tsl::robin_map::erase
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:367
tsl::robin_map::operator!=
friend bool operator!=(const robin_map &lhs, const robin_map &rhs)
Definition: robin_map.h:686
tsl::robin_map::count
size_type count(const K &key) const
Definition: robin_map.h:465
tsl::robin_map::find
const_iterator find(const Key &key) const
Definition: robin_map.h:496
tsl::robin_map::insert
void insert(InputIt first, InputIt last)
Definition: robin_map.h:260
tsl::robin_map::insert
std::pair< iterator, bool > insert(const value_type &value)
Definition: robin_map.h:232
tsl::robin_map::find
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:550
tsl::robin_map::rehash
void rehash(size_type my_count)
Definition: robin_map.h:652
tsl::robin_map< cgsize_t, cgsize_t >::key_type
typename ht::key_type key_type
Definition: robin_map.h:117
tsl::robin_map::begin
const_iterator begin() const noexcept
Definition: robin_map.h:213
tsl::robin_map::max_load_factor
void max_load_factor(float ml)
Definition: robin_map.h:650
tsl::robin_map::operator[]
T & operator[](Key &&key)
Definition: robin_map.h:445
tsl::robin_map::at
const T & at(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:394
tsl::robin_map< cgsize_t, cgsize_t >::hasher
typename ht::hasher hasher
Definition: robin_map.h:122
tsl::robin_map< cgsize_t, cgsize_t >::mapped_type
cgsize_t mapped_type
Definition: robin_map.h:118
tsl::robin_map::insert_or_assign
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition: robin_map.h:267
tsl::detail_robin_hash::robin_hash::at
U::value_type & at(const K &key)
Definition: robin_hash.h:888
tsl::detail_robin_hash::robin_hash::max_size
size_type max_size() const noexcept
Definition: robin_hash.h:671
tsl::robin_map::bucket_count
size_type bucket_count() const
Definition: robin_map.h:630
tsl::robin_map::empty
bool empty() const noexcept
Definition: robin_map.h:223
tsl::detail_robin_hash::robin_hash::rehash
void rehash(size_type new_count)
Definition: robin_hash.h:1020
tsl::detail_robin_hash::robin_hash::insert_hint
iterator insert_hint(const_iterator hint, P &&value)
Definition: robin_hash.h:691
tsl::robin_map::operator=
robin_map & operator=(std::initializer_list< value_type > ilist)
Definition: robin_map.h:197
tsl::robin_map::equal_range
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: robin_map.h:555
tsl::robin_map::ValueSelect::value_type
T value_type
Definition: robin_map.h:103
tsl::robin_map< cgsize_t, cgsize_t >::allocator_type
typename ht::allocator_type allocator_type
Definition: robin_map.h:124
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::const_reference
const value_type & const_reference
Definition: robin_hash.h:347
tsl::detail_robin_hash::robin_hash::clear
void clear() noexcept
Definition: robin_hash.h:676
tsl::robin_map< cgsize_t, cgsize_t >::const_pointer
typename ht::const_pointer const_pointer
Definition: robin_map.h:128
tsl::robin_map::max_size
size_type max_size() const noexcept
Definition: robin_map.h:225
tsl::robin_map::robin_map
robin_map(size_type bucket_count, const Allocator &alloc)
Definition: robin_map.h:144
tsl::robin_map::robin_map
robin_map()
Definition: robin_map.h:136
tsl::robin_map::try_emplace
iterator try_emplace(const_iterator hint, const key_type &k, Args &&... args)
Definition: robin_map.h:321
tsl::detail_robin_hash::robin_hash::reserve
void reserve(size_type new_count)
Definition: robin_hash.h:1026
tsl::robin_map::erase
size_type erase(const K &key)
Definition: robin_map.h:353
robin_hash.h
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::value_type
std::pair< Key, T > value_type
Definition: robin_hash.h:340
tsl::detail_robin_hash::robin_hash::find
iterator find(const K &key)
Definition: robin_hash.h:940
tsl::robin_map< cgsize_t, cgsize_t >::value_type
typename ht::value_type value_type
Definition: robin_map.h:119
tsl::robin_map::count
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:479
tsl::robin_map::try_emplace
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&... args)
Definition: robin_map.h:310
tsl::robin_map::insert_or_assign
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition: robin_map.h:277
tsl::detail_robin_hash::robin_hash::cbegin
const_iterator cbegin() const noexcept
Definition: robin_hash.h:648
tsl::robin_map::key_eq
key_equal key_eq() const
Definition: robin_map.h:659
tsl::robin_map::min_load_factor
void min_load_factor(float ml)
Definition: robin_map.h:649
tsl::robin_map::robin_map
robin_map(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: robin_map.h:185
tsl::detail_robin_hash::robin_hash::count
size_type count(const K &key) const
Definition: robin_hash.h:928
tsl::robin_map::at
const T & at(const Key &key) const
Definition: robin_map.h:389
tsl::detail_robin_hash::has_is_transparent
Definition: robin_hash.h:52
tsl::robin_map::equal_range
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:575
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::DEFAULT_INIT_BUCKETS_SIZE
static const size_type DEFAULT_INIT_BUCKETS_SIZE
Definition: robin_hash.h:1304
tsl::detail_robin_hash::robin_hash::cend
const_iterator cend() const noexcept
Definition: robin_hash.h:662
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::key_equal
KeyEqual key_equal
Definition: robin_hash.h:344
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::const_pointer
const value_type * const_pointer
Definition: robin_hash.h:349
tsl::robin_map::try_emplace
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&... args)
Definition: robin_map.h:315
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::hasher
Hash hasher
Definition: robin_hash.h:343
tsl::robin_map::at
T & at(const Key &key, std::size_t precalculated_hash)
Definition: robin_map.h:384
tsl::robin_map::insert
iterator insert(const_iterator hint, P &&value)
Definition: robin_map.h:250
tsl::detail_robin_hash::robin_hash::erase
iterator erase(iterator pos)
Definition: robin_hash.h:772
tsl::robin_map::m_ht
ht m_ht
Definition: robin_map.h:694
tsl::robin_map::at
T & at(const Key &key)
Definition: robin_map.h:377
tsl::robin_map::find
iterator find(const Key &key)
Definition: robin_map.h:484
tsl::detail_robin_hash::robin_hash
Definition: robin_hash.h:325
tsl::robin_map::equal_range
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:601
tsl::robin_map::load_factor
float load_factor() const
Definition: robin_map.h:636
tsl::detail_robin_hash::robin_hash::mutable_iterator
iterator mutable_iterator(const_iterator pos)
Definition: robin_hash.h:1041
tsl::robin_map::erase
iterator erase(const_iterator pos)
Definition: robin_map.h:333
tsl::robin_map::equal_range
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: robin_map.h:611
tsl::robin_map::robin_map
robin_map(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_map.h:172
tsl::robin_map::find
const_iterator find(const K &key) const
Definition: robin_map.h:536
tsl::robin_map::find
iterator find(const K &key)
Definition: robin_map.h:512
tsl::robin_map::insert_or_assign
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition: robin_map.h:272
tsl::robin_map::find
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:501
tsl::detail_robin_hash::robin_hash::emplace_hint
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: robin_hash.h:745
tsl::robin_map::robin_map
robin_map(InputIt first, InputIt last, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: robin_map.h:157
tsl::robin_map< cgsize_t, cgsize_t >::pointer
typename ht::pointer pointer
Definition: robin_map.h:127
tsl::detail_robin_hash::robin_hash::insert_or_assign
std::pair< iterator, bool > insert_or_assign(K &&key, M &&obj)
Definition: robin_hash.h:718
tsl::robin_map::get_allocator
allocator_type get_allocator() const
Definition: robin_map.h:207
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::const_iterator
robin_iterator< true > const_iterator
Definition: robin_hash.h:351
tsl::robin_map::robin_map
robin_map(std::initializer_list< value_type > init, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: robin_map.h:178
tsl::detail_robin_hash::robin_hash::swap
void swap(robin_hash &other)
Definition: robin_hash.h:865
tsl::robin_map< cgsize_t, cgsize_t >::iterator
typename ht::iterator iterator
Definition: robin_map.h:129
tsl::robin_map::operator==
friend bool operator==(const robin_map &lhs, const robin_map &rhs)
Definition: robin_map.h:670
tsl::detail_robin_hash::robin_hash::min_load_factor
float min_load_factor() const
Definition: robin_hash.h:1003
tsl::robin_map::emplace_hint
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: robin_map.h:304
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::allocator_type
Allocator allocator_type
Definition: robin_hash.h:345
tsl::robin_map::count
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:454
tsl::robin_map::ValueSelect::operator()
const value_type & operator()(const std::pair< Key, T > &key_value) const noexcept
Definition: robin_map.h:105
tsl::robin_map::equal_range
std::pair< iterator, iterator > equal_range(const K &key)
Definition: robin_map.h:587
tsl::robin_map::cbegin
const_iterator cbegin() const noexcept
Definition: robin_map.h:214
tsl::robin_map::reserve
void reserve(size_type my_count)
Definition: robin_map.h:653
tsl::robin_map::robin_map
robin_map(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_map.h:191
tsl::detail_robin_hash::robin_hash::try_emplace_hint
iterator try_emplace_hint(const_iterator hint, K &&key, Args &&... args)
Definition: robin_hash.h:759
tsl::robin_map::robin_map
robin_map(const Allocator &alloc)
Definition: robin_map.h:154
tsl::robin_map::ht
detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy > ht
Definition: robin_map.h:114
tsl::robin_map< cgsize_t, cgsize_t >::reference
typename ht::reference reference
Definition: robin_map.h:125
tsl::robin_map::clear
void clear() noexcept
Definition: robin_map.h:230
tsl::detail_robin_hash::robin_hash::end
iterator end() noexcept
Definition: robin_hash.h:658
tsl::robin_map::robin_map
robin_map(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: robin_map.h:166
tsl::robin_map::count
size_type count(const Key &key) const
Definition: robin_map.h:447
tsl::robin_map::insert
iterator insert(const_iterator hint, const value_type &value)
Definition: robin_map.h:243
tsl::robin_map::swap
friend void swap(robin_map &lhs, robin_map &rhs)
Definition: robin_map.h:691
tsl::robin_map< cgsize_t, cgsize_t >::size_type
typename ht::size_type size_type
Definition: robin_map.h:120
tsl::robin_map< cgsize_t, cgsize_t >::difference_type
typename ht::difference_type difference_type
Definition: robin_map.h:121
tsl::robin_map::at
T & at(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:419
tsl::detail_robin_hash::robin_hash::get_allocator
allocator_type get_allocator() const
Definition: robin_hash.h:631
tsl::robin_map::erase
size_type erase(const key_type &key)
Definition: robin_map.h:335
tsl::robin_map::insert
void insert(std::initializer_list< value_type > ilist)
Definition: robin_map.h:262
tsl::robin_map::equal_range
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:621
tsl::robin_map::insert
std::pair< iterator, bool > insert(value_type &&value)
Definition: robin_map.h:241
tsl::detail_robin_hash::robin_hash::max_bucket_count
size_type max_bucket_count() const
Definition: robin_hash.h:986
tsl::robin_map::KeySelect::key_type
Key key_type
Definition: robin_map.h:90
tsl::robin_map::robin_map
robin_map(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_map.h:149
tsl::robin_map
Definition: robin_map.h:82
tsl::detail_robin_hash::robin_hash::equal_range
std::pair< iterator, iterator > equal_range(const K &key)
Definition: robin_hash.h:957
tsl::robin_map::KeySelect::operator()
const key_type & operator()(const std::pair< Key, T > &key_value) const noexcept
Definition: robin_map.h:92
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::reference
value_type & reference
Definition: robin_hash.h:346
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::key_type
typename KeySelect::key_type key_type
Definition: robin_hash.h:339
tsl::robin_map::erase
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: robin_map.h:342
tsl::robin_map::size
size_type size() const noexcept
Definition: robin_map.h:224
tsl::robin_map::KeySelect::operator()
key_type & operator()(std::pair< Key, T > &key_value) noexcept
Definition: robin_map.h:97
tsl::robin_map::KeySelect
Definition: robin_map.h:87
tsl::robin_map::try_emplace
iterator try_emplace(const_iterator hint, key_type &&k, Args &&... args)
Definition: robin_map.h:327
tsl::detail_robin_hash::robin_hash::bucket_count
size_type bucket_count() const
Definition: robin_hash.h:984
tsl::robin_map::erase
iterator erase(iterator pos)
Definition: robin_map.h:332
tsl::robin_map::insert_or_assign
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition: robin_map.h:282
tsl::detail_robin_hash::robin_hash::try_emplace
std::pair< iterator, bool > try_emplace(K &&key, Args &&... args)
Definition: robin_hash.h:751
tsl::robin_map< cgsize_t, cgsize_t >::const_iterator
typename ht::const_iterator const_iterator
Definition: robin_map.h:130
tsl::detail_robin_hash::robin_hash::begin
iterator begin() noexcept
Definition: robin_hash.h:636
tsl::detail_robin_hash::robin_hash< std::pair< Key, T >, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy >::iterator
robin_iterator< false > iterator
Definition: robin_hash.h:350
tsl::detail_robin_hash::robin_hash::key_eq
key_equal key_eq() const
Definition: robin_hash.h:1036
tsl::robin_map::max_load_factor
float max_load_factor() const
Definition: robin_map.h:639
tsl::detail_robin_hash::robin_hash::insert
std::pair< iterator, bool > insert(P &&value)
Definition: robin_hash.h:686
tsl::robin_map::cend
const_iterator cend() const noexcept
Definition: robin_map.h:218
tsl::detail_robin_hash::robin_hash::load_factor
float load_factor() const
Definition: robin_hash.h:994