File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
include/boost/openmethod/policies Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -194,8 +194,11 @@ void minimal_perfect_hash::fn<Registry>::initialize(
194194 }
195195
196196 // Table size is N * 1.1 to allow up to 10% waste (makes finding hash easier)
197- // Use (N * 11 + 9) / 10 to ensure proper rounding up for small N
198- table_size = (N * 11 + 9 ) / 10 ;
197+ // Formula: ceil(N * 1.1) = (N * 11 + 9) / 10 ensures proper rounding for all N
198+ constexpr std::size_t WASTE_FACTOR_NUMERATOR = 11 ; // 1.1 = 11/10
199+ constexpr std::size_t WASTE_FACTOR_DENOMINATOR = 10 ;
200+ constexpr std::size_t ROUNDING_ADJUSTMENT = 9 ; // For ceiling division
201+ table_size = (N * WASTE_FACTOR_NUMERATOR + ROUNDING_ADJUSTMENT) / WASTE_FACTOR_DENOMINATOR;
199202
200203 if (table_size == 0 ) {
201204 shift = 0 ;
@@ -242,7 +245,6 @@ void minimal_perfect_hash::fn<Registry>::initialize(
242245 constexpr std::size_t DEFAULT_GROUP_DIVISOR = 4 ; // N/4 groups for balance between memory and speed
243246 constexpr std::size_t DISTRIBUTION_FACTOR = 2 ; // 2*N range for better distribution
244247 constexpr std::size_t bits_per_type_id = 8 * sizeof (type_id);
245- // Allow 10% waste to make finding a hash function easier while still being memory-efficient
246248
247249 std::default_random_engine rnd (DEFAULT_RANDOM_SEED);
248250 std::uniform_int_distribution<std::size_t > uniform_dist;
You can’t perform that action at this time.
0 commit comments