15 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
17 #include "absl/container/flat_hash_map.h"
18 #include "absl/container/flat_hash_set.h"
19 #include "absl/container/node_hash_map.h"
20 #include "absl/container/node_hash_set.h"
24 namespace container_internal {
27 #if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
34 template <
class Table>
35 void TestInlineElementSize(
40 std::unordered_set<const HashtablezInfo*>& preexisting_info,
42 size_t expected_element_size) {
43 for (
int i = 0;
i < 10; ++
i) {
47 tables.emplace_back();
49 tables.back().insert(elt);
52 sampler.Iterate([&](
const HashtablezInfo& info) {
53 if (preexisting_info.insert(&info).second) {
54 EXPECT_EQ(info.inline_element_size, expected_element_size);
64 friend bool operator==(
const bigstruct& x,
const bigstruct&
y) {
65 return memcmp(
x.a,
y.a,
sizeof(
x.a)) == 0;
69 return H::combine_contiguous(
std::move(h),
c.a,
sizeof(
c.a));
74 TEST(FlatHashMap, SampleElementSize) {
75 #if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE)
81 std::vector<flat_hash_map<int, bigstruct>> flat_map_tables;
82 std::vector<flat_hash_set<bigstruct>> flat_set_tables;
83 std::vector<node_hash_map<int, bigstruct>> node_map_tables;
84 std::vector<node_hash_set<bigstruct>> node_set_tables;
89 for (
int i = 0;
i < 10000; ++
i) {
90 flat_map_tables.emplace_back();
91 flat_map_tables.back()[
i] = bigstruct{};
97 std::unordered_set<const HashtablezInfo*> preexisting_info;
99 [&](
const HashtablezInfo& info) { preexisting_info.insert(&info); });
100 TestInlineElementSize(sampler, preexisting_info, flat_map_tables,
101 {0, bigstruct{}},
sizeof(
int) +
sizeof(bigstruct));
102 TestInlineElementSize(sampler, preexisting_info, node_map_tables,
103 {0, bigstruct{}},
sizeof(
void*));
104 TestInlineElementSize(sampler, preexisting_info, flat_set_tables,
105 bigstruct{},
sizeof(bigstruct));
106 TestInlineElementSize(sampler, preexisting_info, node_set_tables,
107 bigstruct{},
sizeof(
void*));