diff options
author | Dennis Kormalev <denk@google.com> | 2024-02-07 08:39:23 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-02-07 08:40:46 -0800 |
commit | 643b48a3b4362a932c0e41afce62deb55adf825b (patch) | |
tree | 5e5b68000ddde6fe775e2379b18e7dfa0ad98e11 /absl/container/flat_hash_map.h | |
parent | e22f9c1fdd00f2ad3cfdd1dd7a67145eadc3b21c (diff) | |
download | abseil-643b48a3b4362a932c0e41afce62deb55adf825b.tar.gz abseil-643b48a3b4362a932c0e41afce62deb55adf825b.tar.bz2 abseil-643b48a3b4362a932c0e41afce62deb55adf825b.zip |
Add absl_container_hash-based HashEq specialization
SwissTable provides support for heterogeneous lookup in associative
containers through transparent Hash and Eq types. However, it is not
possible for user types to provide additional specializations to allow
their types to use this functionality.
This CL brings ability for user types to specify their own transparent
absl_container_hash and (optionally) absl_container_eq inner types to
achieve the same functionality.
PiperOrigin-RevId: 604994859
Change-Id: I302486d292c9a18b7d4c77033227008f5539e354
Diffstat (limited to 'absl/container/flat_hash_map.h')
-rw-r--r-- | absl/container/flat_hash_map.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/absl/container/flat_hash_map.h b/absl/container/flat_hash_map.h index 2a1ad0fb..a33c794f 100644 --- a/absl/container/flat_hash_map.h +++ b/absl/container/flat_hash_map.h @@ -62,7 +62,7 @@ struct FlatHashMapPolicy; // * 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. +// 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 @@ -80,6 +80,19 @@ struct FlatHashMapPolicy; // 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 |