summaryrefslogtreecommitdiff
path: root/absl/container/internal/raw_hash_set_benchmark.cc
diff options
context:
space:
mode:
authorGravatar Vitaly Goldshteyn <goldvitaly@google.com>2024-04-02 12:20:51 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-04-02 12:21:50 -0700
commitfbd5fa1781ce6151770557a90d018f71e64e45d0 (patch)
treef246293858b4e7fc689ccef16d75e0a456a6a94d /absl/container/internal/raw_hash_set_benchmark.cc
parent5953a4885ae8dc4baa3f66292d6519e0ec254313 (diff)
Fix bug in BM_EraseIf.
PiperOrigin-RevId: 621258501 Change-Id: Id094f3f0d0bc4a9fa8f3d1f90cfcd4c53beeb776
Diffstat (limited to 'absl/container/internal/raw_hash_set_benchmark.cc')
-rw-r--r--absl/container/internal/raw_hash_set_benchmark.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc
index 05f62d2f..424b72cf 100644
--- a/absl/container/internal/raw_hash_set_benchmark.cc
+++ b/absl/container/internal/raw_hash_set_benchmark.cc
@@ -17,6 +17,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
+#include <limits>
#include <numeric>
#include <random>
#include <string>
@@ -593,14 +594,17 @@ void BM_EraseIf(benchmark::State& state) {
auto& table = tables.back();
for (int64_t i = 0; i < num_elements; i++) {
// We use random keys to reduce noise.
- k.push_back(absl::Uniform<int64_t>(rng, 0, ~int64_t{}));
+ k.push_back(
+ absl::Uniform<int64_t>(rng, 0, std::numeric_limits<int64_t>::max()));
if (!table.insert(k.back()).second) {
k.pop_back();
--i; // duplicated value, retrying
}
}
std::sort(k.begin(), k.end());
- threshold.push_back(k[num_erased]);
+ threshold.push_back(static_cast<int64_t>(num_erased) < num_elements
+ ? k[num_erased]
+ : std::numeric_limits<int64_t>::max());
}
while (state.KeepRunningBatch(static_cast<int64_t>(kRepetitions) *