From d2885bad9428e1a901b7ddf91fa60dfea94632f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Dec 2025 05:35:01 +0000 Subject: [PATCH] Fix table size calculation and documentation for 10% waste Co-authored-by: jll63 <5083077+jll63@users.noreply.github.com> --- .../boost/openmethod/policies/minimal_perfect_hash.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/boost/openmethod/policies/minimal_perfect_hash.hpp b/include/boost/openmethod/policies/minimal_perfect_hash.hpp index c32af66..7835352 100644 --- a/include/boost/openmethod/policies/minimal_perfect_hash.hpp +++ b/include/boost/openmethod/policies/minimal_perfect_hash.hpp @@ -49,7 +49,7 @@ namespace policies { //! determine values for `M` and `N` that result in a minimal perfect hash //! function for the set of registered type_ids. This means that the hash //! function is collision-free and the codomain is approximately the size of -//! the domain, resulting in a dense range [0, n-1] for n inputs. +//! the domain, resulting in a dense range [0, 1.1*n-1] for n inputs. //! //! Unlike @ref fast_perfect_hash, which uses a hash table of size 2^k //! (typically larger than needed) and may have unused slots, this policy @@ -194,10 +194,8 @@ void minimal_perfect_hash::fn::initialize( } // Table size is N * 1.1 to allow up to 10% waste (makes finding hash easier) - table_size = N + N / 10; - if (table_size == N && N > 0) { - table_size = N + 1; // Ensure at least 1 extra slot for N > 0 - } + // Use (N * 11 + 9) / 10 to ensure proper rounding up for small N + table_size = (N * 11 + 9) / 10; if (table_size == 0) { shift = 0;