From 8d2085f6ee19174e9b877d15852a317218073aea Mon Sep 17 00:00:00 2001 From: Erik Rigtorp Date: Sat, 14 Nov 2026 12:54:12 -0500 Subject: [PATCH] Use std::bit_ceil to compute power-of-two bucket count --- include/rigtorp/HashMap.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/rigtorp/HashMap.h b/include/rigtorp/HashMap.h index c336032..fec29f5 100644 --- a/include/rigtorp/HashMap.h +++ b/include/rigtorp/HashMap.h @@ -25,6 +25,7 @@ probing. #pragma once #include +#include #include #include #include @@ -136,10 +137,7 @@ class HashMap { HashMap(size_type bucket_count, key_type empty_key, const allocator_type &alloc = allocator_type()) : empty_key_(empty_key), buckets_(alloc) { - size_t pow2 = 2; - while (pow2 < bucket_count) { - pow2 <<= 1; - } + size_t pow2 = std::bit_ceil(std::max(bucket_count, 2)); buckets_.resize(pow2, std::make_pair(empty_key_, T())); }