File tree Expand file tree Collapse file tree 1 file changed +3
-5
lines changed
include/boost/openmethod/policies Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ namespace policies {
4949// ! determine values for `M` and `N` that result in a minimal perfect hash
5050// ! function for the set of registered type_ids. This means that the hash
5151// ! function is collision-free and the codomain is approximately the size of
52- // ! the domain, resulting in a dense range [0, n-1] for n inputs.
52+ // ! the domain, resulting in a dense range [0, 1.1* n-1] for n inputs.
5353// !
5454// ! Unlike @ref fast_perfect_hash, which uses a hash table of size 2^k
5555// ! (typically larger than needed) and may have unused slots, this policy
@@ -194,10 +194,8 @@ 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- table_size = N + N / 10 ;
198- if (table_size == N && N > 0 ) {
199- table_size = N + 1 ; // Ensure at least 1 extra slot for N > 0
200- }
197+ // Use (N * 11 + 9) / 10 to ensure proper rounding up for small N
198+ table_size = (N * 11 + 9 ) / 10 ;
201199
202200 if (table_size == 0 ) {
203201 shift = 0 ;
You can’t perform that action at this time.
0 commit comments