Commit 08b21bd0 by Dennis Kormalev Committed by Copybara-Service

Add public aliases for default hash/eq types in hash-based containers

Generic user code sometimes wants to provide more flexibility for its
own users and provide type arguments that are used as Hash/Eq in
underlying containers.

However, there is no sensible publicly available default value for it
yet.

This CL fixes this issue and provides publicly visible aliases that such
user code can use.

PiperOrigin-RevId: 627844757
Change-Id: I4c393007244ad8d998da02883c623eae1715c0df
parent b0160ba4
...@@ -66,6 +66,7 @@ set(ABSL_INTERNAL_DLL_FILES ...@@ -66,6 +66,7 @@ set(ABSL_INTERNAL_DLL_FILES
"cleanup/internal/cleanup.h" "cleanup/internal/cleanup.h"
"container/btree_map.h" "container/btree_map.h"
"container/btree_set.h" "container/btree_set.h"
"container/hash_container_defaults.h"
"container/fixed_array.h" "container/fixed_array.h"
"container/flat_hash_map.h" "container/flat_hash_map.h"
"container/flat_hash_set.h" "container/flat_hash_set.h"
......
...@@ -248,7 +248,7 @@ cc_library( ...@@ -248,7 +248,7 @@ cc_library(
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
":container_memory", ":container_memory",
":hash_function_defaults", ":hash_container_defaults",
":raw_hash_map", ":raw_hash_map",
"//absl/algorithm:container", "//absl/algorithm:container",
"//absl/base:core_headers", "//absl/base:core_headers",
...@@ -285,7 +285,7 @@ cc_library( ...@@ -285,7 +285,7 @@ cc_library(
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
":container_memory", ":container_memory",
":hash_function_defaults", ":hash_container_defaults",
":raw_hash_set", ":raw_hash_set",
"//absl/algorithm:container", "//absl/algorithm:container",
"//absl/base:core_headers", "//absl/base:core_headers",
...@@ -324,7 +324,7 @@ cc_library( ...@@ -324,7 +324,7 @@ cc_library(
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
":container_memory", ":container_memory",
":hash_function_defaults", ":hash_container_defaults",
":node_slot_policy", ":node_slot_policy",
":raw_hash_map", ":raw_hash_map",
"//absl/algorithm:container", "//absl/algorithm:container",
...@@ -359,7 +359,7 @@ cc_library( ...@@ -359,7 +359,7 @@ cc_library(
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [ deps = [
":container_memory", ":container_memory",
":hash_function_defaults", ":hash_container_defaults",
":node_slot_policy", ":node_slot_policy",
":raw_hash_set", ":raw_hash_set",
"//absl/algorithm:container", "//absl/algorithm:container",
...@@ -433,6 +433,17 @@ cc_library( ...@@ -433,6 +433,17 @@ cc_library(
], ],
) )
cc_library(
name = "hash_container_defaults",
hdrs = ["hash_container_defaults.h"],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":hash_function_defaults",
"//absl/base:config",
],
)
cc_test( cc_test(
name = "hash_function_defaults_test", name = "hash_function_defaults_test",
srcs = ["internal/hash_function_defaults_test.cc"], srcs = ["internal/hash_function_defaults_test.cc"],
......
...@@ -289,7 +289,7 @@ absl_cc_library( ...@@ -289,7 +289,7 @@ absl_cc_library(
DEPS DEPS
absl::container_memory absl::container_memory
absl::core_headers absl::core_headers
absl::hash_function_defaults absl::hash_container_defaults
absl::raw_hash_map absl::raw_hash_map
absl::algorithm_container absl::algorithm_container
absl::memory absl::memory
...@@ -326,7 +326,7 @@ absl_cc_library( ...@@ -326,7 +326,7 @@ absl_cc_library(
${ABSL_DEFAULT_COPTS} ${ABSL_DEFAULT_COPTS}
DEPS DEPS
absl::container_memory absl::container_memory
absl::hash_function_defaults absl::hash_container_defaults
absl::raw_hash_set absl::raw_hash_set
absl::algorithm_container absl::algorithm_container
absl::core_headers absl::core_headers
...@@ -368,7 +368,7 @@ absl_cc_library( ...@@ -368,7 +368,7 @@ absl_cc_library(
DEPS DEPS
absl::container_memory absl::container_memory
absl::core_headers absl::core_headers
absl::hash_function_defaults absl::hash_container_defaults
absl::node_slot_policy absl::node_slot_policy
absl::raw_hash_map absl::raw_hash_map
absl::algorithm_container absl::algorithm_container
...@@ -404,7 +404,7 @@ absl_cc_library( ...@@ -404,7 +404,7 @@ absl_cc_library(
DEPS DEPS
absl::container_memory absl::container_memory
absl::core_headers absl::core_headers
absl::hash_function_defaults absl::hash_container_defaults
absl::node_slot_policy absl::node_slot_policy
absl::raw_hash_set absl::raw_hash_set
absl::algorithm_container absl::algorithm_container
...@@ -430,6 +430,19 @@ absl_cc_test( ...@@ -430,6 +430,19 @@ absl_cc_test(
GTest::gmock_main GTest::gmock_main
) )
absl_cc_library(
NAME
hash_container_defaults
HDRS
"hash_container_defaults.h"
COPTS
${ABSL_DEFAULT_COPTS}
DEPS
absl::config
absl::hash_function_defaults
PUBLIC
)
# Internal-only target, do not depend on directly. # Internal-only target, do not depend on directly.
absl_cc_library( absl_cc_library(
NAME NAME
......
...@@ -31,16 +31,15 @@ ...@@ -31,16 +31,15 @@
#define ABSL_CONTAINER_FLAT_HASH_MAP_H_ #define ABSL_CONTAINER_FLAT_HASH_MAP_H_
#include <cstddef> #include <cstddef>
#include <new> #include <memory>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/container/hash_container_defaults.h"
#include "absl/container/internal/container_memory.h" #include "absl/container/internal/container_memory.h"
#include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export
#include "absl/container/internal/raw_hash_map.h" // IWYU pragma: export #include "absl/container/internal/raw_hash_map.h" // IWYU pragma: export
#include "absl/memory/memory.h"
namespace absl { namespace absl {
ABSL_NAMESPACE_BEGIN ABSL_NAMESPACE_BEGIN
...@@ -119,9 +118,8 @@ struct FlatHashMapPolicy; ...@@ -119,9 +118,8 @@ struct FlatHashMapPolicy;
// if (result != ducks.end()) { // if (result != ducks.end()) {
// std::cout << "Result: " << result->second << std::endl; // std::cout << "Result: " << result->second << std::endl;
// } // }
template <class K, class V, template <class K, class V, class Hash = DefaultHashContainerHash<K>,
class Hash = absl::container_internal::hash_default_hash<K>, class Eq = DefaultHashContainerEq<K>,
class Eq = absl::container_internal::hash_default_eq<K>,
class Allocator = std::allocator<std::pair<const K, V>>> class Allocator = std::allocator<std::pair<const K, V>>>
class flat_hash_map : public absl::container_internal::raw_hash_map< class flat_hash_map : public absl::container_internal::raw_hash_map<
absl::container_internal::FlatHashMapPolicy<K, V>, absl::container_internal::FlatHashMapPolicy<K, V>,
......
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/macros.h" #include "absl/base/macros.h"
#include "absl/container/hash_container_defaults.h"
#include "absl/container/internal/container_memory.h" #include "absl/container/internal/container_memory.h"
#include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export
#include "absl/container/internal/raw_hash_set.h" // IWYU pragma: export #include "absl/container/internal/raw_hash_set.h" // IWYU pragma: export
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
...@@ -114,8 +114,8 @@ struct FlatHashSetPolicy; ...@@ -114,8 +114,8 @@ struct FlatHashSetPolicy;
// if (ducks.contains("dewey")) { // if (ducks.contains("dewey")) {
// std::cout << "We found dewey!" << std::endl; // std::cout << "We found dewey!" << std::endl;
// } // }
template <class T, class Hash = absl::container_internal::hash_default_hash<T>, template <class T, class Hash = DefaultHashContainerHash<T>,
class Eq = absl::container_internal::hash_default_eq<T>, class Eq = DefaultHashContainerEq<T>,
class Allocator = std::allocator<T>> class Allocator = std::allocator<T>>
class flat_hash_set class flat_hash_set
: public absl::container_internal::raw_hash_set< : public absl::container_internal::raw_hash_set<
......
// Copyright 2024 The Abseil Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ABSL_CONTAINER_HASH_CONTAINER_DEFAULTS_H_
#define ABSL_CONTAINER_HASH_CONTAINER_DEFAULTS_H_
#include "absl/base/config.h"
#include "absl/container/internal/hash_function_defaults.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
// DefaultHashContainerHash is a convenience alias for the functor that is used
// by default by Abseil hash-based (unordered) containers for hashing when
// `Hash` type argument is not explicitly specified.
//
// This type alias can be used by generic code that wants to provide more
// flexibility for defining underlying containers.
template <typename T>
using DefaultHashContainerHash = absl::container_internal::hash_default_hash<T>;
// DefaultHashContainerEq is a convenience alias for the functor that is used by
// default by Abseil hash-based (unordered) containers for equality check when
// `Eq` type argument is not explicitly specified.
//
// This type alias can be used by generic code that wants to provide more
// flexibility for defining underlying containers.
template <typename T>
using DefaultHashContainerEq = absl::container_internal::hash_default_eq<T>;
ABSL_NAMESPACE_END
} // namespace absl
#endif // ABSL_CONTAINER_HASH_CONTAINER_DEFAULTS_H_
...@@ -37,14 +37,13 @@ ...@@ -37,14 +37,13 @@
#define ABSL_CONTAINER_NODE_HASH_MAP_H_ #define ABSL_CONTAINER_NODE_HASH_MAP_H_
#include <cstddef> #include <cstddef>
#include <tuple> #include <memory>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/macros.h" #include "absl/container/hash_container_defaults.h"
#include "absl/container/internal/container_memory.h" #include "absl/container/internal/container_memory.h"
#include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export
#include "absl/container/internal/node_slot_policy.h" #include "absl/container/internal/node_slot_policy.h"
#include "absl/container/internal/raw_hash_map.h" // IWYU pragma: export #include "absl/container/internal/raw_hash_map.h" // IWYU pragma: export
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
...@@ -114,9 +113,8 @@ class NodeHashMapPolicy; ...@@ -114,9 +113,8 @@ class NodeHashMapPolicy;
// if (result != ducks.end()) { // if (result != ducks.end()) {
// std::cout << "Result: " << result->second << std::endl; // std::cout << "Result: " << result->second << std::endl;
// } // }
template <class Key, class Value, template <class Key, class Value, class Hash = DefaultHashContainerHash<Key>,
class Hash = absl::container_internal::hash_default_hash<Key>, class Eq = DefaultHashContainerEq<Key>,
class Eq = absl::container_internal::hash_default_eq<Key>,
class Alloc = std::allocator<std::pair<const Key, Value>>> class Alloc = std::allocator<std::pair<const Key, Value>>>
class node_hash_map class node_hash_map
: public absl::container_internal::raw_hash_map< : public absl::container_internal::raw_hash_map<
......
...@@ -36,12 +36,12 @@ ...@@ -36,12 +36,12 @@
#define ABSL_CONTAINER_NODE_HASH_SET_H_ #define ABSL_CONTAINER_NODE_HASH_SET_H_
#include <cstddef> #include <cstddef>
#include <memory>
#include <type_traits> #include <type_traits>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/macros.h" #include "absl/container/hash_container_defaults.h"
#include "absl/container/internal/container_memory.h" #include "absl/container/internal/container_memory.h"
#include "absl/container/internal/hash_function_defaults.h" // IWYU pragma: export
#include "absl/container/internal/node_slot_policy.h" #include "absl/container/internal/node_slot_policy.h"
#include "absl/container/internal/raw_hash_set.h" // IWYU pragma: export #include "absl/container/internal/raw_hash_set.h" // IWYU pragma: export
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
...@@ -109,9 +109,8 @@ struct NodeHashSetPolicy; ...@@ -109,9 +109,8 @@ struct NodeHashSetPolicy;
// if (ducks.contains("dewey")) { // if (ducks.contains("dewey")) {
// std::cout << "We found dewey!" << std::endl; // std::cout << "We found dewey!" << std::endl;
// } // }
template <class T, class Hash = absl::container_internal::hash_default_hash<T>, template <class T, class Hash = DefaultHashContainerHash<T>,
class Eq = absl::container_internal::hash_default_eq<T>, class Eq = DefaultHashContainerEq<T>, class Alloc = std::allocator<T>>
class Alloc = std::allocator<T>>
class node_hash_set class node_hash_set
: public absl::container_internal::raw_hash_set< : public absl::container_internal::raw_hash_set<
absl::container_internal::NodeHashSetPolicy<T>, Hash, Eq, Alloc> { absl::container_internal::NodeHashSetPolicy<T>, Hash, Eq, Alloc> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment