Commit 03856129 by Evan Brown Committed by Copybara-Service

Add extern templates for common swisstable types.

Motivation: mitigate linker input size increase from swisstable optimizations.

Note: the changes in raw_hash_set.h are fixing build errors that happened when adding the explicit instantiations. The change in unchecked_deref is because set iterators have const reference access whereas map iterators have mutable reference access and the function is never actually called for sets (it's used in raw_hash_map) so it wasn't needed before. I'm not sure why the soo_slot/soo_iterator problems didn't cause compile errors earlier.
PiperOrigin-RevId: 615174043
Change-Id: Iac5eb2332a76e9b70021156fbb2b8def47a5391d
parent 3c1f9be7
...@@ -68,7 +68,9 @@ set(ABSL_INTERNAL_DLL_FILES ...@@ -68,7 +68,9 @@ set(ABSL_INTERNAL_DLL_FILES
"container/btree_set.h" "container/btree_set.h"
"container/fixed_array.h" "container/fixed_array.h"
"container/flat_hash_map.h" "container/flat_hash_map.h"
"container/flat_hash_map.cc"
"container/flat_hash_set.h" "container/flat_hash_set.h"
"container/flat_hash_set.cc"
"container/inlined_vector.h" "container/inlined_vector.h"
"container/internal/btree.h" "container/internal/btree.h"
"container/internal/btree_container.h" "container/internal/btree_container.h"
...@@ -91,7 +93,9 @@ set(ABSL_INTERNAL_DLL_FILES ...@@ -91,7 +93,9 @@ set(ABSL_INTERNAL_DLL_FILES
"container/internal/raw_hash_set.h" "container/internal/raw_hash_set.h"
"container/internal/tracked.h" "container/internal/tracked.h"
"container/node_hash_map.h" "container/node_hash_map.h"
"container/node_hash_map.cc"
"container/node_hash_set.h" "container/node_hash_set.h"
"container/node_hash_set.cc"
"crc/crc32c.cc" "crc/crc32c.cc"
"crc/crc32c.h" "crc/crc32c.h"
"crc/internal/cpu_detect.cc" "crc/internal/cpu_detect.cc"
......
...@@ -242,6 +242,7 @@ NOTEST_TAGS_MOBILE = [ ...@@ -242,6 +242,7 @@ NOTEST_TAGS_MOBILE = [
cc_library( cc_library(
name = "flat_hash_map", name = "flat_hash_map",
srcs = ["flat_hash_map.cc"],
hdrs = ["flat_hash_map.h"], hdrs = ["flat_hash_map.h"],
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
...@@ -249,7 +250,9 @@ cc_library( ...@@ -249,7 +250,9 @@ cc_library(
":container_memory", ":container_memory",
":hash_function_defaults", ":hash_function_defaults",
":raw_hash_map", ":raw_hash_map",
":raw_hash_set",
"//absl/algorithm:container", "//absl/algorithm:container",
"//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
"//absl/memory", "//absl/memory",
], ],
...@@ -279,6 +282,7 @@ cc_test( ...@@ -279,6 +282,7 @@ cc_test(
cc_library( cc_library(
name = "flat_hash_set", name = "flat_hash_set",
srcs = ["flat_hash_set.cc"],
hdrs = ["flat_hash_set.h"], hdrs = ["flat_hash_set.h"],
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
...@@ -287,6 +291,7 @@ cc_library( ...@@ -287,6 +291,7 @@ cc_library(
":hash_function_defaults", ":hash_function_defaults",
":raw_hash_set", ":raw_hash_set",
"//absl/algorithm:container", "//absl/algorithm:container",
"//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
"//absl/memory", "//absl/memory",
], ],
...@@ -318,6 +323,7 @@ cc_test( ...@@ -318,6 +323,7 @@ cc_test(
cc_library( cc_library(
name = "node_hash_map", name = "node_hash_map",
srcs = ["node_hash_map.cc"],
hdrs = ["node_hash_map.h"], hdrs = ["node_hash_map.h"],
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
...@@ -326,7 +332,9 @@ cc_library( ...@@ -326,7 +332,9 @@ cc_library(
":hash_function_defaults", ":hash_function_defaults",
":node_slot_policy", ":node_slot_policy",
":raw_hash_map", ":raw_hash_map",
":raw_hash_set",
"//absl/algorithm:container", "//absl/algorithm:container",
"//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
"//absl/memory", "//absl/memory",
], ],
...@@ -353,6 +361,7 @@ cc_test( ...@@ -353,6 +361,7 @@ cc_test(
cc_library( cc_library(
name = "node_hash_set", name = "node_hash_set",
srcs = ["node_hash_set.cc"],
hdrs = ["node_hash_set.h"], hdrs = ["node_hash_set.h"],
copts = ABSL_DEFAULT_COPTS, copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS, linkopts = ABSL_DEFAULT_LINKOPTS,
...@@ -362,6 +371,7 @@ cc_library( ...@@ -362,6 +371,7 @@ cc_library(
":node_slot_policy", ":node_slot_policy",
":raw_hash_set", ":raw_hash_set",
"//absl/algorithm:container", "//absl/algorithm:container",
"//absl/base:config",
"//absl/base:core_headers", "//absl/base:core_headers",
"//absl/memory", "//absl/memory",
], ],
......
...@@ -283,13 +283,17 @@ absl_cc_library( ...@@ -283,13 +283,17 @@ absl_cc_library(
flat_hash_map flat_hash_map
HDRS HDRS
"flat_hash_map.h" "flat_hash_map.h"
SRCS
"flat_hash_map.cc"
COPTS COPTS
${ABSL_DEFAULT_COPTS} ${ABSL_DEFAULT_COPTS}
DEPS DEPS
absl::config
absl::container_memory absl::container_memory
absl::core_headers absl::core_headers
absl::hash_function_defaults absl::hash_function_defaults
absl::raw_hash_map absl::raw_hash_map
absl::raw_hash_set
absl::algorithm_container absl::algorithm_container
absl::memory absl::memory
PUBLIC PUBLIC
...@@ -321,9 +325,12 @@ absl_cc_library( ...@@ -321,9 +325,12 @@ absl_cc_library(
flat_hash_set flat_hash_set
HDRS HDRS
"flat_hash_set.h" "flat_hash_set.h"
SRCS
"flat_hash_set.cc"
COPTS COPTS
${ABSL_DEFAULT_COPTS} ${ABSL_DEFAULT_COPTS}
DEPS DEPS
absl::config
absl::container_memory absl::container_memory
absl::hash_function_defaults absl::hash_function_defaults
absl::raw_hash_set absl::raw_hash_set
...@@ -362,14 +369,18 @@ absl_cc_library( ...@@ -362,14 +369,18 @@ absl_cc_library(
node_hash_map node_hash_map
HDRS HDRS
"node_hash_map.h" "node_hash_map.h"
SRCS
"node_hash_map.cc"
COPTS COPTS
${ABSL_DEFAULT_COPTS} ${ABSL_DEFAULT_COPTS}
DEPS DEPS
absl::config
absl::container_memory absl::container_memory
absl::core_headers absl::core_headers
absl::hash_function_defaults absl::hash_function_defaults
absl::node_slot_policy absl::node_slot_policy
absl::raw_hash_map absl::raw_hash_map
absl::raw_hash_set
absl::algorithm_container absl::algorithm_container
absl::memory absl::memory
PUBLIC PUBLIC
...@@ -398,9 +409,12 @@ absl_cc_library( ...@@ -398,9 +409,12 @@ absl_cc_library(
node_hash_set node_hash_set
HDRS HDRS
"node_hash_set.h" "node_hash_set.h"
SRCS
"node_hash_set.cc"
COPTS COPTS
${ABSL_DEFAULT_COPTS} ${ABSL_DEFAULT_COPTS}
DEPS DEPS
absl::config
absl::container_memory absl::container_memory
absl::core_headers absl::core_headers
absl::hash_function_defaults absl::hash_function_defaults
......
// 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.
#include "absl/container/flat_hash_map.h"
#include <cstdint>
#include <string>
#include "absl/base/config.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, int32_t, int32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, std::string, int32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, int32_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, int64_t, int64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, std::string, int64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, int64_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, uint32_t, uint32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, std::string, uint32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, uint32_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, uint64_t, uint64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, std::string, uint64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, uint64_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(template, std::string, std::string);
ABSL_NAMESPACE_END
} // namespace absl
...@@ -31,15 +31,20 @@ ...@@ -31,15 +31,20 @@
#define ABSL_CONTAINER_FLAT_HASH_MAP_H_ #define ABSL_CONTAINER_FLAT_HASH_MAP_H_
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <memory>
#include <new> #include <new>
#include <string>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/config.h"
#include "absl/base/macros.h" #include "absl/base/macros.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/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/container/internal/raw_hash_set.h" // IWYU pragma: export
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
namespace absl { namespace absl {
...@@ -632,6 +637,42 @@ struct IsUnorderedContainer< ...@@ -632,6 +637,42 @@ struct IsUnorderedContainer<
} // namespace container_algorithm_internal } // namespace container_algorithm_internal
// Explicit template instantiations for common map types in order to decrease
// linker input size. Note that explicitly instantiating flat_hash_map itself
// doesn't help because it has no non-alias members. If we need to decrease
// linker input size more, we could potentially (a) add more key/value types,
// e.g. string_view/Cord, (b) instantiate some template member functions, e.g.
// operator[]/find. The EXTERN argument is `extern` for the declaration and
// empty for the definition.
#define ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(TEMPLATE, KEY, VALUE) \
TEMPLATE class absl::container_internal::raw_hash_map< \
absl::container_internal::FlatHashMapPolicy<KEY, VALUE>, \
absl::container_internal::hash_default_hash<KEY>, \
absl::container_internal::hash_default_eq<KEY>, \
std::allocator<std::pair<const KEY, VALUE>>>; \
TEMPLATE class absl::container_internal::raw_hash_set< \
absl::container_internal::FlatHashMapPolicy<KEY, VALUE>, \
absl::container_internal::hash_default_hash<KEY>, \
absl::container_internal::hash_default_eq<KEY>, \
std::allocator<std::pair<const KEY, VALUE>>>;
// We use exact-width integer types rather than `int`/`long`/`long long` because
// these are the types recommended in the Google C++ style guide and which are
// commonly used in Google code.
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, int32_t, int32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, std::string, int32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, int32_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, int64_t, int64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, std::string, int64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, int64_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, uint32_t, uint32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, std::string, uint32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, uint32_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, uint64_t, uint64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, std::string, uint64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, uint64_t, std::string);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_MAP(extern template, std::string, std::string);
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
// 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.
#include "absl/container/flat_hash_set.h"
#include <cstdint>
#include <string>
#include "absl/base/config.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, int8_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, int16_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, int32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, int64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, uint8_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, uint16_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, uint32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, uint64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(template, std::string);
ABSL_NAMESPACE_END
} // namespace absl
...@@ -30,11 +30,14 @@ ...@@ -30,11 +30,14 @@
#define ABSL_CONTAINER_FLAT_HASH_SET_H_ #define ABSL_CONTAINER_FLAT_HASH_SET_H_
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <memory> #include <memory>
#include <string>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/config.h"
#include "absl/base/macros.h" #include "absl/base/macros.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/hash_function_defaults.h" // IWYU pragma: export
...@@ -523,6 +526,32 @@ struct IsUnorderedContainer<absl::flat_hash_set<Key, Hash, KeyEqual, Allocator>> ...@@ -523,6 +526,32 @@ struct IsUnorderedContainer<absl::flat_hash_set<Key, Hash, KeyEqual, Allocator>>
} // namespace container_algorithm_internal } // namespace container_algorithm_internal
// Explicit template instantiations for common set types in order to decrease
// linker input size. Note that explicitly instantiating flat_hash_set itself
// doesn't help because it has no non-alias members. If we need to decrease
// linker input size more, we could potentially (a) add more key types, e.g.
// string_view/Cord, (b) instantiate some template member functions, e.g.
// find/insert/emplace. The EXTERN argument is `extern` for the declaration and
// empty for the definition.
#define ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(TEMPLATE, KEY) \
TEMPLATE class absl::container_internal::raw_hash_set< \
absl::container_internal::FlatHashSetPolicy<KEY>, \
absl::container_internal::hash_default_hash<KEY>, \
absl::container_internal::hash_default_eq<KEY>, std::allocator<KEY>>;
// We use exact-width integer types rather than `int`/`long`/`long long` because
// these are the types recommended in the Google C++ style guide and which are
// commonly used in Google code.
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, int8_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, int16_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, int32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, int64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, uint8_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, uint16_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, uint32_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, uint64_t);
ABSL_INTERNAL_TEMPLATE_FLAT_HASH_SET(extern template, std::string);
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
...@@ -1839,7 +1839,7 @@ class HashSetResizeHelper { ...@@ -1839,7 +1839,7 @@ class HashSetResizeHelper {
// Reads `capacity` and updates all other fields based on the result of // Reads `capacity` and updates all other fields based on the result of
// the allocation. // the allocation.
// //
// It also may do the folowing actions: // It also may do the following actions:
// 1. initialize control bytes // 1. initialize control bytes
// 2. initialize slots // 2. initialize slots
// 3. deallocate old slots. // 3. deallocate old slots.
...@@ -2204,9 +2204,14 @@ class raw_hash_set { ...@@ -2204,9 +2204,14 @@ class raw_hash_set {
bool is_soo() const { return fits_in_soo(capacity()); } bool is_soo() const { return fits_in_soo(capacity()); }
bool is_full_soo() const { return is_soo() && !empty(); } bool is_full_soo() const { return is_soo() && !empty(); }
// Give an early error when key_type is not hashable/eq. // Give an early error when key_type is not hashable/eq. Definitions are
auto KeyTypeCanBeHashed(const Hash& h, const key_type& k) -> decltype(h(k)); // provided because otherwise explicit template instantiation fails on MSVC.
auto KeyTypeCanBeEq(const Eq& eq, const key_type& k) -> decltype(eq(k, k)); auto KeyTypeCanBeHashed(const Hash& h, const key_type& k) -> decltype(h(k)) {
ABSL_UNREACHABLE();
}
auto KeyTypeCanBeEq(const Eq& eq, const key_type& k) -> decltype(eq(k, k)) {
ABSL_UNREACHABLE();
}
using AllocTraits = absl::allocator_traits<allocator_type>; using AllocTraits = absl::allocator_traits<allocator_type>;
using SlotAlloc = typename absl::allocator_traits< using SlotAlloc = typename absl::allocator_traits<
...@@ -2395,7 +2400,18 @@ class raw_hash_set { ...@@ -2395,7 +2400,18 @@ class raw_hash_set {
const_iterator operator++(int) { return inner_++; } const_iterator operator++(int) { return inner_++; }
friend bool operator==(const const_iterator& a, const const_iterator& b) { friend bool operator==(const const_iterator& a, const const_iterator& b) {
// Suppress erroneous uninitialized memory errors on GCC. This seems to be
// because the slot pointer in the inner_ iterator is uninitialized, even
// though that pointer is not used when uninitialized.
// Similar bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112637.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
return a.inner_ == b.inner_; return a.inner_ == b.inner_;
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} }
friend bool operator!=(const const_iterator& a, const const_iterator& b) { friend bool operator!=(const const_iterator& a, const const_iterator& b) {
return !(a == b); return !(a == b);
...@@ -3719,7 +3735,9 @@ class raw_hash_set { ...@@ -3719,7 +3735,9 @@ class raw_hash_set {
return const_cast<raw_hash_set*>(this)->iterator_at(i); return const_cast<raw_hash_set*>(this)->iterator_at(i);
} }
reference unchecked_deref(iterator it) { return it.unchecked_deref(); } reference unchecked_deref(iterator it) {
return const_cast<reference>(it.unchecked_deref());
}
private: private:
friend struct RawHashSetTestOnlyAccess; friend struct RawHashSetTestOnlyAccess;
...@@ -3769,13 +3787,13 @@ class raw_hash_set { ...@@ -3769,13 +3787,13 @@ class raw_hash_set {
return static_cast<slot_type*>(common().soo_data()); return static_cast<slot_type*>(common().soo_data());
} }
const slot_type* soo_slot() const { const slot_type* soo_slot() const {
return reinterpret_cast<raw_hash_set*>(this)->soo_slot(); return const_cast<raw_hash_set*>(this)->soo_slot();
} }
iterator soo_iterator() { iterator soo_iterator() {
return {SooControl(), soo_slot(), common().generation_ptr()}; return {SooControl(), soo_slot(), common().generation_ptr()};
} }
const_iterator soo_iterator() const { const_iterator soo_iterator() const {
return reinterpret_cast<raw_hash_set*>(this)->soo_iterator(); return const_cast<raw_hash_set*>(this)->soo_iterator();
} }
HashtablezInfoHandle infoz() { HashtablezInfoHandle infoz() {
assert(!is_soo()); assert(!is_soo());
......
// 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.
#include "absl/container/node_hash_map.h"
#include <cstdint>
#include <string>
#include "absl/base/config.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, int32_t, int32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, std::string, int32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, int32_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, int64_t, int64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, std::string, int64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, int64_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, uint32_t, uint32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, std::string, uint32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, uint32_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, uint64_t, uint64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, std::string, uint64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, uint64_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(template, std::string, std::string);
ABSL_NAMESPACE_END
} // namespace absl
...@@ -37,11 +37,15 @@ ...@@ -37,11 +37,15 @@
#define ABSL_CONTAINER_NODE_HASH_MAP_H_ #define ABSL_CONTAINER_NODE_HASH_MAP_H_
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/config.h"
#include "absl/base/macros.h" #include "absl/base/macros.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/hash_function_defaults.h" // IWYU pragma: export
...@@ -623,6 +627,42 @@ struct IsUnorderedContainer< ...@@ -623,6 +627,42 @@ struct IsUnorderedContainer<
} // namespace container_algorithm_internal } // namespace container_algorithm_internal
// Explicit template instantiations for common map types in order to decrease
// linker input size. Note that explicitly instantiating node_hash_map itself
// doesn't help because it has no non-alias members. If we need to decrease
// linker input size more, we could potentially (a) add more key/value types,
// e.g. string_view/Cord, (b) instantiate some template member functions, e.g.
// operator[]/find. The EXTERN argument is `extern` for the declaration and
// empty for the definition.
#define ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(TEMPLATE, KEY, VALUE) \
TEMPLATE class absl::container_internal::raw_hash_map< \
absl::container_internal::NodeHashMapPolicy<KEY, VALUE>, \
absl::container_internal::hash_default_hash<KEY>, \
absl::container_internal::hash_default_eq<KEY>, \
std::allocator<std::pair<const KEY, VALUE>>>; \
TEMPLATE class absl::container_internal::raw_hash_set< \
absl::container_internal::NodeHashMapPolicy<KEY, VALUE>, \
absl::container_internal::hash_default_hash<KEY>, \
absl::container_internal::hash_default_eq<KEY>, \
std::allocator<std::pair<const KEY, VALUE>>>;
// We use exact-width integer types rather than `int`/`long`/`long long` because
// these are the types recommended in the Google C++ style guide and which are
// commonly used in Google code.
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, int32_t, int32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, std::string, int32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, int32_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, int64_t, int64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, std::string, int64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, int64_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, uint32_t, uint32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, std::string, uint32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, uint32_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, uint64_t, uint64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, std::string, uint64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, uint64_t, std::string);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_MAP(extern template, std::string, std::string);
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
// 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.
#include "absl/container/node_hash_set.h"
#include <cstdint>
#include <string>
#include "absl/base/config.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, int8_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, int16_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, int32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, int64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, uint8_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, uint16_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, uint32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, uint64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(template, std::string);
ABSL_NAMESPACE_END
} // namespace absl
...@@ -36,9 +36,13 @@ ...@@ -36,9 +36,13 @@
#define ABSL_CONTAINER_NODE_HASH_SET_H_ #define ABSL_CONTAINER_NODE_HASH_SET_H_
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <type_traits> #include <type_traits>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/base/config.h"
#include "absl/base/macros.h" #include "absl/base/macros.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/hash_function_defaults.h" // IWYU pragma: export
...@@ -518,6 +522,32 @@ struct IsUnorderedContainer<absl::node_hash_set<Key, Hash, KeyEqual, Allocator>> ...@@ -518,6 +522,32 @@ struct IsUnorderedContainer<absl::node_hash_set<Key, Hash, KeyEqual, Allocator>>
: std::true_type {}; : std::true_type {};
} // namespace container_algorithm_internal } // namespace container_algorithm_internal
// Explicit template instantiations for common set types in order to decrease
// linker input size. Note that explicitly instantiating node_hash_set itself
// doesn't help because it has no non-alias members. If we need to decrease
// linker input size more, we could potentially (a) add more key types, e.g.
// string_view/Cord, (b) instantiate some template member functions, e.g.
// find/insert/emplace.
#define ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(TEMPLATE, KEY) \
TEMPLATE class absl::container_internal::raw_hash_set< \
absl::container_internal::NodeHashSetPolicy<KEY>, \
absl::container_internal::hash_default_hash<KEY>, \
absl::container_internal::hash_default_eq<KEY>, std::allocator<KEY>>;
// We use exact-width integer types rather than `int`/`long`/`long long` because
// these are the types recommended in the Google C++ style guide and which are
// commonly used in Google code.
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int8_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int16_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, int64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint8_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint16_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint32_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, uint64_t);
ABSL_INTERNAL_TEMPLATE_NODE_HASH_SET(extern template, std::string);
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
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