From 816fbc5d86582c95a374f21213705901fbcd7ecd Mon Sep 17 00:00:00 2001 From: Daniel Kral Date: Sat, 14 Mar 2026 16:42:15 +0100 Subject: [PATCH 1/5] Replace `float` with `double` in hashed_index.hpp --- include/boost/multi_index/hashed_index.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/boost/multi_index/hashed_index.hpp b/include/boost/multi_index/hashed_index.hpp index f12c9244..35206977 100644 --- a/include/boost/multi_index/hashed_index.hpp +++ b/include/boost/multi_index/hashed_index.hpp @@ -710,10 +710,10 @@ class hashed_index:protected SuperMeta::type /* hash policy */ - float load_factor()const BOOST_NOEXCEPT - {return static_cast(size())/bucket_count();} - float max_load_factor()const BOOST_NOEXCEPT{return mlf;} - void max_load_factor(float z){mlf=z;calculate_max_load();} + double load_factor()const BOOST_NOEXCEPT + {return static_cast(size())/bucket_count();} + double max_load_factor()const BOOST_NOEXCEPT{return mlf;} + void max_load_factor(double z){mlf=z;calculate_max_load();} void rehash(size_type n) { @@ -721,7 +721,7 @@ class hashed_index:protected SuperMeta::type if(size()<=max_load&&n<=bucket_count())return; size_type bc =(std::numeric_limits::max)(); - float fbc=1.0f+static_cast(size())/mlf; + double fbc=1.0f+static_cast(size())/mlf; if(bc>fbc){ bc=static_cast(fbc); if(bc(std::ceil(static_cast(n)/mlf))); + rehash(static_cast(std::ceil(static_cast(n)/mlf))); } protected: @@ -1422,7 +1422,7 @@ class hashed_index:protected SuperMeta::type void calculate_max_load() { - float fml=mlf*static_cast(bucket_count()); + double fml=mlf*static_cast(bucket_count()); max_load=(std::numeric_limits::max)(); if(max_load>fml)max_load=static_cast(fml); } @@ -1431,7 +1431,7 @@ class hashed_index:protected SuperMeta::type { if(n>max_load){ size_type bc =(std::numeric_limits::max)(); - float fbc=1.0f+static_cast(n)/mlf; + double fbc=1.0f+static_cast(n)/mlf; if(bc>fbc)bc =static_cast(fbc); unchecked_rehash(bc); } @@ -1735,7 +1735,7 @@ class hashed_index:protected SuperMeta::type hasher hash_; key_equal eq_; bucket_array_type buckets; - float mlf; + double mlf; size_type max_load; #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) From 8ba5327d98c9d9459c4466c5091f60c35dd6986c Mon Sep 17 00:00:00 2001 From: Daniel Kral Date: Sat, 11 Apr 2026 08:55:06 +0200 Subject: [PATCH 2/5] Fix formatting indents --- include/boost/multi_index/hashed_index.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/multi_index/hashed_index.hpp b/include/boost/multi_index/hashed_index.hpp index 35206977..980de3de 100644 --- a/include/boost/multi_index/hashed_index.hpp +++ b/include/boost/multi_index/hashed_index.hpp @@ -721,7 +721,7 @@ class hashed_index:protected SuperMeta::type if(size()<=max_load&&n<=bucket_count())return; size_type bc =(std::numeric_limits::max)(); - double fbc=1.0f+static_cast(size())/mlf; + double fbc=1.0f+static_cast(size())/mlf; if(bc>fbc){ bc=static_cast(fbc); if(bcmax_load){ size_type bc =(std::numeric_limits::max)(); - double fbc=1.0f+static_cast(n)/mlf; + double fbc=1.0f+static_cast(n)/mlf; if(bc>fbc)bc =static_cast(fbc); unchecked_rehash(bc); } @@ -1735,7 +1735,7 @@ class hashed_index:protected SuperMeta::type hasher hash_; key_equal eq_; bucket_array_type buckets; - double mlf; + double mlf; size_type max_load; #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) From d4e2872f1b6e840d5160786b483196b2ae934631 Mon Sep 17 00:00:00 2001 From: Daniel Kral Date: Thu, 23 Apr 2026 17:15:17 +0200 Subject: [PATCH 3/5] Reset changes --- include/boost/multi_index/hashed_index.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/boost/multi_index/hashed_index.hpp b/include/boost/multi_index/hashed_index.hpp index 980de3de..f12c9244 100644 --- a/include/boost/multi_index/hashed_index.hpp +++ b/include/boost/multi_index/hashed_index.hpp @@ -710,10 +710,10 @@ class hashed_index:protected SuperMeta::type /* hash policy */ - double load_factor()const BOOST_NOEXCEPT - {return static_cast(size())/bucket_count();} - double max_load_factor()const BOOST_NOEXCEPT{return mlf;} - void max_load_factor(double z){mlf=z;calculate_max_load();} + float load_factor()const BOOST_NOEXCEPT + {return static_cast(size())/bucket_count();} + float max_load_factor()const BOOST_NOEXCEPT{return mlf;} + void max_load_factor(float z){mlf=z;calculate_max_load();} void rehash(size_type n) { @@ -721,7 +721,7 @@ class hashed_index:protected SuperMeta::type if(size()<=max_load&&n<=bucket_count())return; size_type bc =(std::numeric_limits::max)(); - double fbc=1.0f+static_cast(size())/mlf; + float fbc=1.0f+static_cast(size())/mlf; if(bc>fbc){ bc=static_cast(fbc); if(bc(std::ceil(static_cast(n)/mlf))); + rehash(static_cast(std::ceil(static_cast(n)/mlf))); } protected: @@ -1422,7 +1422,7 @@ class hashed_index:protected SuperMeta::type void calculate_max_load() { - double fml=mlf*static_cast(bucket_count()); + float fml=mlf*static_cast(bucket_count()); max_load=(std::numeric_limits::max)(); if(max_load>fml)max_load=static_cast(fml); } @@ -1431,7 +1431,7 @@ class hashed_index:protected SuperMeta::type { if(n>max_load){ size_type bc =(std::numeric_limits::max)(); - double fbc=1.0f+static_cast(n)/mlf; + float fbc=1.0f+static_cast(n)/mlf; if(bc>fbc)bc =static_cast(fbc); unchecked_rehash(bc); } @@ -1735,7 +1735,7 @@ class hashed_index:protected SuperMeta::type hasher hash_; key_equal eq_; bucket_array_type buckets; - double mlf; + float mlf; size_type max_load; #if defined(BOOST_MULTI_INDEX_ENABLE_SAFE_MODE) From 270b3d65c896631c65eb93dc8945a3999f4e72b2 Mon Sep 17 00:00:00 2001 From: Daniel Kral Date: Thu, 23 Apr 2026 17:17:44 +0200 Subject: [PATCH 4/5] Add fix from PR comment comment: https://github.com/boostorg/multi_index/pull/94#issuecomment-4283474290 --- include/boost/multi_index/hashed_index.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/multi_index/hashed_index.hpp b/include/boost/multi_index/hashed_index.hpp index f12c9244..54f1bb0d 100644 --- a/include/boost/multi_index/hashed_index.hpp +++ b/include/boost/multi_index/hashed_index.hpp @@ -1432,7 +1432,7 @@ class hashed_index:protected SuperMeta::type if(n>max_load){ size_type bc =(std::numeric_limits::max)(); float fbc=1.0f+static_cast(n)/mlf; - if(bc>fbc)bc =static_cast(fbc); + if(bc>fbc)bc =(std::max)(static_cast(fbc),bucket_count()+1); unchecked_rehash(bc); } } From dfad53004a21423aae7572c6d2f47169651ecf1d Mon Sep 17 00:00:00 2001 From: joaquintides Date: Thu, 23 Apr 2026 19:25:36 +0200 Subject: [PATCH 5/5] forced both args of std::max to the same type --- include/boost/multi_index/hashed_index.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/boost/multi_index/hashed_index.hpp b/include/boost/multi_index/hashed_index.hpp index 54f1bb0d..b183e378 100644 --- a/include/boost/multi_index/hashed_index.hpp +++ b/include/boost/multi_index/hashed_index.hpp @@ -1,4 +1,4 @@ -/* Copyright 2003-2025 Joaquin M Lopez Munoz. +/* Copyright 2003-2026 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) @@ -1432,7 +1432,11 @@ class hashed_index:protected SuperMeta::type if(n>max_load){ size_type bc =(std::numeric_limits::max)(); float fbc=1.0f+static_cast(n)/mlf; - if(bc>fbc)bc =(std::max)(static_cast(fbc),bucket_count()+1); + if(bc>fbc){ + bc =(std::max)( + static_cast(fbc), + static_cast(bucket_count()+1)); + } unchecked_rehash(bc); } }