about summary refs log tree commit diff
path: root/absl/container/internal/raw_hash_set_test.cc
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-04-01T21·06-0700
committerGennadiy Rozental <rogeeff@google.com>2019-04-01T22·15-0400
commit93dfcf74cb5fccae3da07897d8613ae6cab958a0 (patch)
tree04896cfc845d55a724a1aac5589caf2045fc33a9 /absl/container/internal/raw_hash_set_test.cc
parent2c8421e1c6cef0da9e8a20b01c15256ec9ec116d (diff)
Export of internal Abseil changes.
--
855576faf9556573fd74c2874b290d8feb6565d5 by Gennadiy Rozental <rogeeff@google.com>:

Import of CCTZ from GitHub.

PiperOrigin-RevId: 241395451

--
b93bfd43eb2a992258f131e10f503526cfec6d48 by CJ Johnson <johnsoncj@google.com>:

Fixes comment over AbslHashValue for InlinedVector

PiperOrigin-RevId: 241368320

--
75f58dafcac7d78c28d92a61ec7e53c5b3b86697 by Matt Kulukundis <kfm@google.com>:

Do not call sampling logic for tables with custom allocators.

PiperOrigin-RevId: 241356451

--
09f1b4889476ff707a54189aff540e2fe1edcf61 by Derek Mauro <dmauro@google.com>:

Re-enable optionalTest.InPlaceTSFINAEBug after libc++ update

PiperOrigin-RevId: 241222673

--
01a8bb5a8cb1e13e88ddb92f9c0160beb6e126be by Derek Mauro <dmauro@google.com>:

Update Clang on Kokoro to r356196.

This includes a workaround for a -Wgnu-include-next warning fixed by
https://reviews.llvm.org/rG0706e144d57305782988dd4367530ae04986116f

PiperOrigin-RevId: 241222395

--
1de66bb669a7ec1494d6064677687f761ee2d369 by Abseil Team <absl-team@google.com>:

Remove identical test and fix char to string per comment

PiperOrigin-RevId: 240855512
GitOrigin-RevId: 855576faf9556573fd74c2874b290d8feb6565d5
Change-Id: Ie155b209ef5567e6597da6ef1844db7e2ad72586
Diffstat (limited to 'absl/container/internal/raw_hash_set_test.cc')
-rw-r--r--absl/container/internal/raw_hash_set_test.cc41
1 files changed, 40 insertions, 1 deletions
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc
index 7d96ed90be9c..871d85f139a1 100644
--- a/absl/container/internal/raw_hash_set_test.cc
+++ b/absl/container/internal/raw_hash_set_test.cc
@@ -343,7 +343,25 @@ struct IntTable
     : raw_hash_set<IntPolicy, container_internal::hash_default_hash<int64_t>,
                    std::equal_to<int64_t>, std::allocator<int64_t>> {
   using Base = typename IntTable::raw_hash_set;
-  IntTable() {}
+  using Base::Base;
+};
+
+template <typename T>
+struct CustomAlloc : std::allocator<T> {
+  CustomAlloc() {}
+
+  template <typename U>
+  CustomAlloc(const CustomAlloc<U>& other) {}
+
+  template<class U> struct rebind {
+    using other = CustomAlloc<U>;
+  };
+};
+
+struct CustomAllocIntTable
+    : raw_hash_set<IntPolicy, container_internal::hash_default_hash<int64_t>,
+                   std::equal_to<int64_t>, CustomAlloc<int64_t>> {
+  using Base = typename CustomAllocIntTable::raw_hash_set;
   using Base::Base;
 };
 
@@ -1869,6 +1887,27 @@ TEST(RawHashSamplerTest, Sample) {
               0.01, 0.005);
 }
 
+TEST(RawHashSamplerTest, DoNotSampleCustomAllocators) {
+  // Enable the feature even if the prod default is off.
+  SetHashtablezEnabled(true);
+  SetHashtablezSampleParameter(100);
+
+  auto& sampler = HashtablezSampler::Global();
+  size_t start_size = 0;
+  start_size += sampler.Iterate([&](const HashtablezInfo&) { ++start_size; });
+
+  std::vector<CustomAllocIntTable> tables;
+  for (int i = 0; i < 1000000; ++i) {
+    tables.emplace_back();
+    tables.back().insert(1);
+  }
+  size_t end_size = 0;
+  end_size += sampler.Iterate([&](const HashtablezInfo&) { ++end_size; });
+
+  EXPECT_NEAR((end_size - start_size) / static_cast<double>(tables.size()),
+              0.00, 0.001);
+}
+
 #ifdef ADDRESS_SANITIZER
 TEST(Sanitizer, PoisoningUnused) {
   IntTable t;