template <class K, class V, class Hash = absl::container_internal::hash_default_hash<K>, class Eq = absl::container_internal::hash_default_eq<K>, class Allocator = std::allocator<std::pair<const K, V>>>

class flat_hash_map

Defined at line 126 of file ../../third_party/abseil-cpp/absl/container/flat_hash_map.h

-----------------------------------------------------------------------------

absl::flat_hash_map

-----------------------------------------------------------------------------

An `absl::flat_hash_map

<K

, V>` is an unordered associative container which

has been optimized for both speed and memory footprint in most common use

cases. Its interface is similar to that of `std::unordered_map

<K

, V>` with

the following notable differences:

* Requires keys that are CopyConstructible

* Requires values that are MoveConstructible

* Supports heterogeneous lookup, through `find()`, `operator[]()` and

`insert()`, provided that the map is provided a compatible heterogeneous

hashing function and equality operator. See below for details.

* Invalidates any references and pointers to elements within the table after

`rehash()` and when the table is moved.

* Contains a `capacity()` member function indicating the number of element

slots (open, deleted, and empty) within the hash map.

* Returns `void` from the `erase(iterator)` overload.

By default, `flat_hash_map` uses the `absl::Hash` hashing framework.

All fundamental and Abseil types that support the `absl::Hash` framework have

a compatible equality operator for comparing insertions into `flat_hash_map`.

If your type is not yet supported by the `absl::Hash` framework, see

absl/hash/hash.h for information on extending Abseil hashing to user-defined

types.

Using `absl::flat_hash_map` at interface boundaries in dynamically loaded

libraries (e.g. .dll, .so) is unsupported due to way `absl::Hash` values may

be randomized across dynamically loaded libraries.

To achieve heterogeneous lookup for custom types either `Hash` and `Eq` type

parameters can be used or `T` should have public inner types

`absl_container_hash` and (optionally) `absl_container_eq`. In either case,

`typename Hash::is_transparent` and `typename Eq::is_transparent` should be

well-formed. Both types are basically functors:

* `Hash` should support `size_t operator()(U val) const` that returns a hash

for the given `val`.

* `Eq` should support `bool operator()(U lhs, V rhs) const` that returns true

if `lhs` is equal to `rhs`.

In most cases `T` needs only to provide the `absl_container_hash`. In this

case `std::equal_to

<void

>` will be used instead of `eq` part.

NOTE: A `flat_hash_map` stores its value types directly inside its

implementation array to avoid memory indirection. Because a `flat_hash_map`

is designed to move data when rehashed, map values will not retain pointer

stability. If you require pointer stability, or if your values are large,

consider using `absl::flat_hash_map

<Key

, std::unique_ptr

<Value

>>` instead.

If your types are not moveable or you require pointer stability for keys,

consider `absl::node_hash_map`.

Example:

// Create a flat hash map of three strings (that map to strings)

absl::flat_hash_map

<std

::string, std::string> ducks =

{{"a", "huey"}, {"b", "dewey"}, {"c", "louie"}};

// Insert a new element into the flat hash map

ducks.insert({"d", "donald"});

// Force a rehash of the flat hash map

ducks.rehash(0);

// Find the element with the key "b"

std::string search_key = "b";

auto result = ducks.find(search_key);

if (result != ducks.end()) {

std::cout

<

<

"Result: "

<

<

result->second

<

<

std::endl;

}

Public Methods

void flat_hash_map<K, V, Hash, Eq, Allocator> ()

Constructors and Assignment Operators

A flat_hash_map supports the same overload set as `std::unordered_map`

for construction and assignment:

* Default constructor

// No allocation for the table's elements is made.

absl::flat_hash_map

<int

, std::string> map1;

* Initializer List constructor

absl::flat_hash_map

<int

, std::string> map2 =

{{1, "huey"}, {2, "dewey"}, {3, "louie"},};

* Copy constructor

absl::flat_hash_map

<int

, std::string> map3(map2);

* Copy assignment operator

// Hash functor and Comparator are copied as well

absl::flat_hash_map

<int

, std::string> map4;

map4 = map3;

* Move constructor

// Move is guaranteed efficient

absl::flat_hash_map

<int

, std::string> map5(std::move(map4));

* Move assignment operator

// May be efficient if allocators are compatible

absl::flat_hash_map

<int

, std::string> map6;

map6 = std::move(map5);

* Range constructor

std::vector

<std

::pair

<int

, std::string>> v = {{1, "a"}, {2, "b"}};

absl::flat_hash_map

<int

, std::string> map7(v.begin(), v.end());

Defined at line 172 of file ../../third_party/abseil-cpp/absl/container/flat_hash_map.h