@@ -88,7 +88,7 @@ struct minimal_perfect_hash : type_hash {
8888 static std::size_t shift;
8989 static std::size_t table_size; // N for minimal perfect hash
9090 static std::size_t num_groups;
91- static std::size_t group_mult;
91+ static std::uint32_t group_mult; // Smaller type to avoid overflow
9292 static std::size_t group_shift;
9393
9494 static void check (std::size_t index, type_id type);
@@ -179,7 +179,7 @@ template<class Registry>
179179std::size_t minimal_perfect_hash::fn<Registry>::num_groups;
180180
181181template <class Registry >
182- std::size_t minimal_perfect_hash::fn<Registry>::group_mult;
182+ std::uint32_t minimal_perfect_hash::fn<Registry>::group_mult;
183183
184184template <class Registry >
185185std::size_t minimal_perfect_hash::fn<Registry>::group_shift;
@@ -275,7 +275,10 @@ void minimal_perfect_hash::fn<Registry>::initialize(
275275 // Try different pilot hash parameters
276276 for (std::size_t pass = 0 ; pass < MAX_PASSES && total_attempts < MAX_ATTEMPTS; ++pass) {
277277 mult = uniform_dist (rnd) | 1 ;
278- group_mult = uniform_dist (rnd) | 1 ;
278+ // Use a smaller multiplier for group hash to avoid overflow
279+ // We only need enough bits to distinguish between num_groups
280+ std::uniform_int_distribution<std::uint32_t > group_dist;
281+ group_mult = group_dist (rnd) | 1 ;
279282
280283 // Calculate M for pilot hash (number of bits for table_size range)
281284 std::size_t M = 0 ;
0 commit comments