• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // -----------------------------------------------------------------------------
16 // File: flat_hash_map.h
17 // -----------------------------------------------------------------------------
18 //
19 // An `absl::flat_hash_map<K, V>` is an unordered associative container of
20 // unique keys and associated values designed to be a more efficient replacement
21 // for `std::unordered_map`. Like `unordered_map`, search, insertion, and
22 // deletion of map elements can be done as an `O(1)` operation. However,
23 // `flat_hash_map` (and other unordered associative containers known as the
24 // collection of Abseil "Swiss tables") contain other optimizations that result
25 // in both memory and computation advantages.
26 //
27 // In most cases, your default choice for a hash map should be a map of type
28 // `flat_hash_map`.
29 
30 #ifndef ABSL_CONTAINER_FLAT_HASH_MAP_H_
31 #define ABSL_CONTAINER_FLAT_HASH_MAP_H_
32 
33 #include <cstddef>
34 #include <memory>
35 #include <type_traits>
36 #include <utility>
37 
38 #include "absl/algorithm/container.h"
39 #include "absl/base/macros.h"
40 #include "absl/container/hash_container_defaults.h"
41 #include "absl/container/internal/container_memory.h"
42 #include "absl/container/internal/raw_hash_map.h"  // IWYU pragma: export
43 
44 namespace absl {
45 ABSL_NAMESPACE_BEGIN
46 namespace container_internal {
47 template <class K, class V>
48 struct FlatHashMapPolicy;
49 }  // namespace container_internal
50 
51 // -----------------------------------------------------------------------------
52 // absl::flat_hash_map
53 // -----------------------------------------------------------------------------
54 //
55 // An `absl::flat_hash_map<K, V>` is an unordered associative container which
56 // has been optimized for both speed and memory footprint in most common use
57 // cases. Its interface is similar to that of `std::unordered_map<K, V>` with
58 // the following notable differences:
59 //
60 // * Requires keys that are CopyConstructible
61 // * Requires values that are MoveConstructible
62 // * Supports heterogeneous lookup, through `find()`, `operator[]()` and
63 //   `insert()`, provided that the map is provided a compatible heterogeneous
64 //   hashing function and equality operator. See below for details.
65 // * Invalidates any references and pointers to elements within the table after
66 //   `rehash()` and when the table is moved.
67 // * Contains a `capacity()` member function indicating the number of element
68 //   slots (open, deleted, and empty) within the hash map.
69 // * Returns `void` from the `erase(iterator)` overload.
70 //
71 // By default, `flat_hash_map` uses the `absl::Hash` hashing framework.
72 // All fundamental and Abseil types that support the `absl::Hash` framework have
73 // a compatible equality operator for comparing insertions into `flat_hash_map`.
74 // If your type is not yet supported by the `absl::Hash` framework, see
75 // absl/hash/hash.h for information on extending Abseil hashing to user-defined
76 // types.
77 //
78 // Using `absl::flat_hash_map` at interface boundaries in dynamically loaded
79 // libraries (e.g. .dll, .so) is unsupported due to way `absl::Hash` values may
80 // be randomized across dynamically loaded libraries.
81 //
82 // To achieve heterogeneous lookup for custom types either `Hash` and `Eq` type
83 // parameters can be used or `T` should have public inner types
84 // `absl_container_hash` and (optionally) `absl_container_eq`. In either case,
85 // `typename Hash::is_transparent` and `typename Eq::is_transparent` should be
86 // well-formed. Both types are basically functors:
87 // * `Hash` should support `size_t operator()(U val) const` that returns a hash
88 // for the given `val`.
89 // * `Eq` should support `bool operator()(U lhs, V rhs) const` that returns true
90 // if `lhs` is equal to `rhs`.
91 //
92 // In most cases `T` needs only to provide the `absl_container_hash`. In this
93 // case `std::equal_to<void>` will be used instead of `eq` part.
94 //
95 // NOTE: A `flat_hash_map` stores its value types directly inside its
96 // implementation array to avoid memory indirection. Because a `flat_hash_map`
97 // is designed to move data when rehashed, map values will not retain pointer
98 // stability. If you require pointer stability, or if your values are large,
99 // consider using `absl::flat_hash_map<Key, std::unique_ptr<Value>>` instead.
100 // If your types are not moveable or you require pointer stability for keys,
101 // consider `absl::node_hash_map`.
102 //
103 // Example:
104 //
105 //   // Create a flat hash map of three strings (that map to strings)
106 //   absl::flat_hash_map<std::string, std::string> ducks =
107 //     {{"a", "huey"}, {"b", "dewey"}, {"c", "louie"}};
108 //
109 //  // Insert a new element into the flat hash map
110 //  ducks.insert({"d", "donald"});
111 //
112 //  // Force a rehash of the flat hash map
113 //  ducks.rehash(0);
114 //
115 //  // Find the element with the key "b"
116 //  std::string search_key = "b";
117 //  auto result = ducks.find(search_key);
118 //  if (result != ducks.end()) {
119 //    std::cout << "Result: " << result->second << std::endl;
120 //  }
121 template <class K, class V, class Hash = DefaultHashContainerHash<K>,
122           class Eq = DefaultHashContainerEq<K>,
123           class Allocator = std::allocator<std::pair<const K, V>>>
124 class flat_hash_map : public absl::container_internal::raw_hash_map<
125                           absl::container_internal::FlatHashMapPolicy<K, V>,
126                           Hash, Eq, Allocator> {
127   using Base = typename flat_hash_map::raw_hash_map;
128 
129  public:
130   // Constructors and Assignment Operators
131   //
132   // A flat_hash_map supports the same overload set as `std::unordered_map`
133   // for construction and assignment:
134   //
135   // *  Default constructor
136   //
137   //    // No allocation for the table's elements is made.
138   //    absl::flat_hash_map<int, std::string> map1;
139   //
140   // * Initializer List constructor
141   //
142   //   absl::flat_hash_map<int, std::string> map2 =
143   //       {{1, "huey"}, {2, "dewey"}, {3, "louie"},};
144   //
145   // * Copy constructor
146   //
147   //   absl::flat_hash_map<int, std::string> map3(map2);
148   //
149   // * Copy assignment operator
150   //
151   //  // Hash functor and Comparator are copied as well
152   //  absl::flat_hash_map<int, std::string> map4;
153   //  map4 = map3;
154   //
155   // * Move constructor
156   //
157   //   // Move is guaranteed efficient
158   //   absl::flat_hash_map<int, std::string> map5(std::move(map4));
159   //
160   // * Move assignment operator
161   //
162   //   // May be efficient if allocators are compatible
163   //   absl::flat_hash_map<int, std::string> map6;
164   //   map6 = std::move(map5);
165   //
166   // * Range constructor
167   //
168   //   std::vector<std::pair<int, std::string>> v = {{1, "a"}, {2, "b"}};
169   //   absl::flat_hash_map<int, std::string> map7(v.begin(), v.end());
flat_hash_map()170   flat_hash_map() {}
171   using Base::Base;
172 
173   // flat_hash_map::begin()
174   //
175   // Returns an iterator to the beginning of the `flat_hash_map`.
176   using Base::begin;
177 
178   // flat_hash_map::cbegin()
179   //
180   // Returns a const iterator to the beginning of the `flat_hash_map`.
181   using Base::cbegin;
182 
183   // flat_hash_map::cend()
184   //
185   // Returns a const iterator to the end of the `flat_hash_map`.
186   using Base::cend;
187 
188   // flat_hash_map::end()
189   //
190   // Returns an iterator to the end of the `flat_hash_map`.
191   using Base::end;
192 
193   // flat_hash_map::capacity()
194   //
195   // Returns the number of element slots (assigned, deleted, and empty)
196   // available within the `flat_hash_map`.
197   //
198   // NOTE: this member function is particular to `absl::flat_hash_map` and is
199   // not provided in the `std::unordered_map` API.
200   using Base::capacity;
201 
202   // flat_hash_map::empty()
203   //
204   // Returns whether or not the `flat_hash_map` is empty.
205   using Base::empty;
206 
207   // flat_hash_map::max_size()
208   //
209   // Returns the largest theoretical possible number of elements within a
210   // `flat_hash_map` under current memory constraints. This value can be thought
211   // of the largest value of `std::distance(begin(), end())` for a
212   // `flat_hash_map<K, V>`.
213   using Base::max_size;
214 
215   // flat_hash_map::size()
216   //
217   // Returns the number of elements currently within the `flat_hash_map`.
218   using Base::size;
219 
220   // flat_hash_map::clear()
221   //
222   // Removes all elements from the `flat_hash_map`. Invalidates any references,
223   // pointers, or iterators referring to contained elements.
224   //
225   // NOTE: this operation may shrink the underlying buffer. To avoid shrinking
226   // the underlying buffer call `erase(begin(), end())`.
227   using Base::clear;
228 
229   // flat_hash_map::erase()
230   //
231   // Erases elements within the `flat_hash_map`. Erasing does not trigger a
232   // rehash. Overloads are listed below.
233   //
234   // void erase(const_iterator pos):
235   //
236   //   Erases the element at `position` of the `flat_hash_map`, returning
237   //   `void`.
238   //
239   //   NOTE: returning `void` in this case is different than that of STL
240   //   containers in general and `std::unordered_map` in particular (which
241   //   return an iterator to the element following the erased element). If that
242   //   iterator is needed, simply post increment the iterator:
243   //
244   //     map.erase(it++);
245   //
246   // iterator erase(const_iterator first, const_iterator last):
247   //
248   //   Erases the elements in the open interval [`first`, `last`), returning an
249   //   iterator pointing to `last`. The special case of calling
250   //   `erase(begin(), end())` resets the reserved growth such that if
251   //   `reserve(N)` has previously been called and there has been no intervening
252   //   call to `clear()`, then after calling `erase(begin(), end())`, it is safe
253   //   to assume that inserting N elements will not cause a rehash.
254   //
255   // size_type erase(const key_type& key):
256   //
257   //   Erases the element with the matching key, if it exists, returning the
258   //   number of elements erased (0 or 1).
259   using Base::erase;
260 
261   // flat_hash_map::insert()
262   //
263   // Inserts an element of the specified value into the `flat_hash_map`,
264   // returning an iterator pointing to the newly inserted element, provided that
265   // an element with the given key does not already exist. If rehashing occurs
266   // due to the insertion, all iterators are invalidated. Overloads are listed
267   // below.
268   //
269   // std::pair<iterator,bool> insert(const init_type& value):
270   //
271   //   Inserts a value into the `flat_hash_map`. Returns a pair consisting of an
272   //   iterator to the inserted element (or to the element that prevented the
273   //   insertion) and a bool denoting whether the insertion took place.
274   //
275   // std::pair<iterator,bool> insert(T&& value):
276   // std::pair<iterator,bool> insert(init_type&& value):
277   //
278   //   Inserts a moveable value into the `flat_hash_map`. Returns a pair
279   //   consisting of an iterator to the inserted element (or to the element that
280   //   prevented the insertion) and a bool denoting whether the insertion took
281   //   place.
282   //
283   // iterator insert(const_iterator hint, const init_type& value):
284   // iterator insert(const_iterator hint, T&& value):
285   // iterator insert(const_iterator hint, init_type&& value);
286   //
287   //   Inserts a value, using the position of `hint` as a non-binding suggestion
288   //   for where to begin the insertion search. Returns an iterator to the
289   //   inserted element, or to the existing element that prevented the
290   //   insertion.
291   //
292   // void insert(InputIterator first, InputIterator last):
293   //
294   //   Inserts a range of values [`first`, `last`).
295   //
296   //   NOTE: Although the STL does not specify which element may be inserted if
297   //   multiple keys compare equivalently, for `flat_hash_map` we guarantee the
298   //   first match is inserted.
299   //
300   // void insert(std::initializer_list<init_type> ilist):
301   //
302   //   Inserts the elements within the initializer list `ilist`.
303   //
304   //   NOTE: Although the STL does not specify which element may be inserted if
305   //   multiple keys compare equivalently within the initializer list, for
306   //   `flat_hash_map` we guarantee the first match is inserted.
307   using Base::insert;
308 
309   // flat_hash_map::insert_or_assign()
310   //
311   // Inserts an element of the specified value into the `flat_hash_map` provided
312   // that a value with the given key does not already exist, or replaces it with
313   // the element value if a key for that value already exists, returning an
314   // iterator pointing to the newly inserted element.  If rehashing occurs due
315   // to the insertion, all existing iterators are invalidated. Overloads are
316   // listed below.
317   //
318   // pair<iterator, bool> insert_or_assign(const init_type& k, T&& obj):
319   // pair<iterator, bool> insert_or_assign(init_type&& k, T&& obj):
320   //
321   //   Inserts/Assigns (or moves) the element of the specified key into the
322   //   `flat_hash_map`.
323   //
324   // iterator insert_or_assign(const_iterator hint,
325   //                           const init_type& k, T&& obj):
326   // iterator insert_or_assign(const_iterator hint, init_type&& k, T&& obj):
327   //
328   //   Inserts/Assigns (or moves) the element of the specified key into the
329   //   `flat_hash_map` using the position of `hint` as a non-binding suggestion
330   //   for where to begin the insertion search.
331   using Base::insert_or_assign;
332 
333   // flat_hash_map::emplace()
334   //
335   // Inserts an element of the specified value by constructing it in-place
336   // within the `flat_hash_map`, provided that no element with the given key
337   // already exists.
338   //
339   // The element may be constructed even if there already is an element with the
340   // key in the container, in which case the newly constructed element will be
341   // destroyed immediately. Prefer `try_emplace()` unless your key is not
342   // copyable or moveable.
343   //
344   // If rehashing occurs due to the insertion, all iterators are invalidated.
345   using Base::emplace;
346 
347   // flat_hash_map::emplace_hint()
348   //
349   // Inserts an element of the specified value by constructing it in-place
350   // within the `flat_hash_map`, using the position of `hint` as a non-binding
351   // suggestion for where to begin the insertion search, and only inserts
352   // provided that no element with the given key already exists.
353   //
354   // The element may be constructed even if there already is an element with the
355   // key in the container, in which case the newly constructed element will be
356   // destroyed immediately. Prefer `try_emplace()` unless your key is not
357   // copyable or moveable.
358   //
359   // If rehashing occurs due to the insertion, all iterators are invalidated.
360   using Base::emplace_hint;
361 
362   // flat_hash_map::try_emplace()
363   //
364   // Inserts an element of the specified value by constructing it in-place
365   // within the `flat_hash_map`, provided that no element with the given key
366   // already exists. Unlike `emplace()`, if an element with the given key
367   // already exists, we guarantee that no element is constructed.
368   //
369   // If rehashing occurs due to the insertion, all iterators are invalidated.
370   // Overloads are listed below.
371   //
372   //   pair<iterator, bool> try_emplace(const key_type& k, Args&&... args):
373   //   pair<iterator, bool> try_emplace(key_type&& k, Args&&... args):
374   //
375   // Inserts (via copy or move) the element of the specified key into the
376   // `flat_hash_map`.
377   //
378   //   iterator try_emplace(const_iterator hint,
379   //                        const key_type& k, Args&&... args):
380   //   iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args):
381   //
382   // Inserts (via copy or move) the element of the specified key into the
383   // `flat_hash_map` using the position of `hint` as a non-binding suggestion
384   // for where to begin the insertion search.
385   //
386   // All `try_emplace()` overloads make the same guarantees regarding rvalue
387   // arguments as `std::unordered_map::try_emplace()`, namely that these
388   // functions will not move from rvalue arguments if insertions do not happen.
389   using Base::try_emplace;
390 
391   // flat_hash_map::extract()
392   //
393   // Extracts the indicated element, erasing it in the process, and returns it
394   // as a C++17-compatible node handle. Overloads are listed below.
395   //
396   // node_type extract(const_iterator position):
397   //
398   //   Extracts the key,value pair of the element at the indicated position and
399   //   returns a node handle owning that extracted data.
400   //
401   // node_type extract(const key_type& x):
402   //
403   //   Extracts the key,value pair of the element with a key matching the passed
404   //   key value and returns a node handle owning that extracted data. If the
405   //   `flat_hash_map` does not contain an element with a matching key, this
406   //   function returns an empty node handle.
407   //
408   // NOTE: when compiled in an earlier version of C++ than C++17,
409   // `node_type::key()` returns a const reference to the key instead of a
410   // mutable reference. We cannot safely return a mutable reference without
411   // std::launder (which is not available before C++17).
412   using Base::extract;
413 
414   // flat_hash_map::merge()
415   //
416   // Extracts elements from a given `source` flat hash map into this
417   // `flat_hash_map`. If the destination `flat_hash_map` already contains an
418   // element with an equivalent key, that element is not extracted.
419   using Base::merge;
420 
421   // flat_hash_map::swap(flat_hash_map& other)
422   //
423   // Exchanges the contents of this `flat_hash_map` with those of the `other`
424   // flat hash map, avoiding invocation of any move, copy, or swap operations on
425   // individual elements.
426   //
427   // All iterators and references on the `flat_hash_map` remain valid, excepting
428   // for the past-the-end iterator, which is invalidated.
429   //
430   // `swap()` requires that the flat hash map's hashing and key equivalence
431   // functions be Swappable, and are exchanged using unqualified calls to
432   // non-member `swap()`. If the map's allocator has
433   // `std::allocator_traits<allocator_type>::propagate_on_container_swap::value`
434   // set to `true`, the allocators are also exchanged using an unqualified call
435   // to non-member `swap()`; otherwise, the allocators are not swapped.
436   using Base::swap;
437 
438   // flat_hash_map::rehash(count)
439   //
440   // Rehashes the `flat_hash_map`, setting the number of slots to be at least
441   // the passed value. If the new number of slots increases the load factor more
442   // than the current maximum load factor
443   // (`count` < `size()` / `max_load_factor()`), then the new number of slots
444   // will be at least `size()` / `max_load_factor()`.
445   //
446   // To force a rehash, pass rehash(0).
447   //
448   // NOTE: unlike behavior in `std::unordered_map`, references are also
449   // invalidated upon a `rehash()`.
450   using Base::rehash;
451 
452   // flat_hash_map::reserve(count)
453   //
454   // Sets the number of slots in the `flat_hash_map` to the number needed to
455   // accommodate at least `count` total elements without exceeding the current
456   // maximum load factor, and may rehash the container if needed.
457   using Base::reserve;
458 
459   // flat_hash_map::at()
460   //
461   // Returns a reference to the mapped value of the element with key equivalent
462   // to the passed key.
463   using Base::at;
464 
465   // flat_hash_map::contains()
466   //
467   // Determines whether an element with a key comparing equal to the given `key`
468   // exists within the `flat_hash_map`, returning `true` if so or `false`
469   // otherwise.
470   using Base::contains;
471 
472   // flat_hash_map::count(const Key& key) const
473   //
474   // Returns the number of elements with a key comparing equal to the given
475   // `key` within the `flat_hash_map`. note that this function will return
476   // either `1` or `0` since duplicate keys are not allowed within a
477   // `flat_hash_map`.
478   using Base::count;
479 
480   // flat_hash_map::equal_range()
481   //
482   // Returns a closed range [first, last], defined by a `std::pair` of two
483   // iterators, containing all elements with the passed key in the
484   // `flat_hash_map`.
485   using Base::equal_range;
486 
487   // flat_hash_map::find()
488   //
489   // Finds an element with the passed `key` within the `flat_hash_map`.
490   using Base::find;
491 
492   // flat_hash_map::operator[]()
493   //
494   // Returns a reference to the value mapped to the passed key within the
495   // `flat_hash_map`, performing an `insert()` if the key does not already
496   // exist.
497   //
498   // If an insertion occurs and results in a rehashing of the container, all
499   // iterators are invalidated. Otherwise iterators are not affected and
500   // references are not invalidated. Overloads are listed below.
501   //
502   // T& operator[](const Key& key):
503   //
504   //   Inserts an init_type object constructed in-place if the element with the
505   //   given key does not exist.
506   //
507   // T& operator[](Key&& key):
508   //
509   //   Inserts an init_type object constructed in-place provided that an element
510   //   with the given key does not exist.
511   using Base::operator[];
512 
513   // flat_hash_map::bucket_count()
514   //
515   // Returns the number of "buckets" within the `flat_hash_map`. Note that
516   // because a flat hash map contains all elements within its internal storage,
517   // this value simply equals the current capacity of the `flat_hash_map`.
518   using Base::bucket_count;
519 
520   // flat_hash_map::load_factor()
521   //
522   // Returns the current load factor of the `flat_hash_map` (the average number
523   // of slots occupied with a value within the hash map).
524   using Base::load_factor;
525 
526   // flat_hash_map::max_load_factor()
527   //
528   // Manages the maximum load factor of the `flat_hash_map`. Overloads are
529   // listed below.
530   //
531   // float flat_hash_map::max_load_factor()
532   //
533   //   Returns the current maximum load factor of the `flat_hash_map`.
534   //
535   // void flat_hash_map::max_load_factor(float ml)
536   //
537   //   Sets the maximum load factor of the `flat_hash_map` to the passed value.
538   //
539   //   NOTE: This overload is provided only for API compatibility with the STL;
540   //   `flat_hash_map` will ignore any set load factor and manage its rehashing
541   //   internally as an implementation detail.
542   using Base::max_load_factor;
543 
544   // flat_hash_map::get_allocator()
545   //
546   // Returns the allocator function associated with this `flat_hash_map`.
547   using Base::get_allocator;
548 
549   // flat_hash_map::hash_function()
550   //
551   // Returns the hashing function used to hash the keys within this
552   // `flat_hash_map`.
553   using Base::hash_function;
554 
555   // flat_hash_map::key_eq()
556   //
557   // Returns the function used for comparing keys equality.
558   using Base::key_eq;
559 };
560 
561 // erase_if(flat_hash_map<>, Pred)
562 //
563 // Erases all elements that satisfy the predicate `pred` from the container `c`.
564 // Returns the number of erased elements.
565 template <typename K, typename V, typename H, typename E, typename A,
566           typename Predicate>
erase_if(flat_hash_map<K,V,H,E,A> & c,Predicate pred)567 typename flat_hash_map<K, V, H, E, A>::size_type erase_if(
568     flat_hash_map<K, V, H, E, A>& c, Predicate pred) {
569   return container_internal::EraseIf(pred, &c);
570 }
571 
572 namespace container_internal {
573 
574 template <class K, class V>
575 struct FlatHashMapPolicy {
576   using slot_policy = container_internal::map_slot_policy<K, V>;
577   using slot_type = typename slot_policy::slot_type;
578   using key_type = K;
579   using mapped_type = V;
580   using init_type = std::pair</*non const*/ key_type, mapped_type>;
581 
582   template <class Allocator, class... Args>
constructFlatHashMapPolicy583   static void construct(Allocator* alloc, slot_type* slot, Args&&... args) {
584     slot_policy::construct(alloc, slot, std::forward<Args>(args)...);
585   }
586 
587   // Returns std::true_type in case destroy is trivial.
588   template <class Allocator>
destroyFlatHashMapPolicy589   static auto destroy(Allocator* alloc, slot_type* slot) {
590     return slot_policy::destroy(alloc, slot);
591   }
592 
593   template <class Allocator>
transferFlatHashMapPolicy594   static auto transfer(Allocator* alloc, slot_type* new_slot,
595                        slot_type* old_slot) {
596     return slot_policy::transfer(alloc, new_slot, old_slot);
597   }
598 
599   template <class F, class... Args>
decltypeFlatHashMapPolicy600   static decltype(absl::container_internal::DecomposePair(
601       std::declval<F>(), std::declval<Args>()...))
602   apply(F&& f, Args&&... args) {
603     return absl::container_internal::DecomposePair(std::forward<F>(f),
604                                                    std::forward<Args>(args)...);
605   }
606 
607   template <class Hash>
get_hash_slot_fnFlatHashMapPolicy608   static constexpr HashSlotFn get_hash_slot_fn() {
609     return memory_internal::IsLayoutCompatible<K, V>::value
610                ? &TypeErasedApplyToSlotFn<Hash, K>
611                : nullptr;
612   }
613 
space_usedFlatHashMapPolicy614   static size_t space_used(const slot_type*) { return 0; }
615 
elementFlatHashMapPolicy616   static std::pair<const K, V>& element(slot_type* slot) { return slot->value; }
617 
valueFlatHashMapPolicy618   static V& value(std::pair<const K, V>* kv) { return kv->second; }
valueFlatHashMapPolicy619   static const V& value(const std::pair<const K, V>* kv) { return kv->second; }
620 };
621 
622 }  // namespace container_internal
623 
624 namespace container_algorithm_internal {
625 
626 // Specialization of trait in absl/algorithm/container.h
627 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
628 struct IsUnorderedContainer<
629     absl::flat_hash_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type {};
630 
631 }  // namespace container_algorithm_internal
632 
633 ABSL_NAMESPACE_END
634 }  // namespace absl
635 
636 #endif  // ABSL_CONTAINER_FLAT_HASH_MAP_H_
637