mirror of
https://github.com/FEX-Emu/robin-map.git
synced 2024-11-23 06:09:52 +00:00
Fix issue #23. The 'distance_type' used to store the distance of a value in a bucket from its ideal bucket could overflow when a lot of collisions happened and the load_factor() stayed below REHASH_ON_HIGH_NB_PROBES__MIN_LOAD_FACTOR. We now rehash no matter the load factor if the distance becomes too high.
This commit is contained in:
parent
8d650f9a01
commit
73959d62e3
@ -293,6 +293,11 @@ private:
|
||||
tsl_rh_assert(!empty());
|
||||
value().~value_type();
|
||||
}
|
||||
|
||||
public:
|
||||
static const distance_type DIST_FROM_IDEAL_BUCKET_LIMIT = 512;
|
||||
static_assert(DIST_FROM_IDEAL_BUCKET_LIMIT <= std::numeric_limits<distance_type>::max() - 1,
|
||||
"DIST_FROM_IDEAL_BUCKET_LIMIT must be <= std::numeric_limits<distance_type>::max() - 1.");
|
||||
|
||||
private:
|
||||
using storage = typename std::aligned_storage<sizeof(value_type), alignof(value_type)>::type;
|
||||
@ -1266,9 +1271,7 @@ private:
|
||||
|
||||
while(!m_buckets[ibucket].empty()) {
|
||||
if(dist_from_ideal_bucket > m_buckets[ibucket].dist_from_ideal_bucket()) {
|
||||
if(dist_from_ideal_bucket >= REHASH_ON_HIGH_NB_PROBES__NPROBES &&
|
||||
load_factor() >= REHASH_ON_HIGH_NB_PROBES__MIN_LOAD_FACTOR)
|
||||
{
|
||||
if(dist_from_ideal_bucket >= bucket_entry::DIST_FROM_IDEAL_BUCKET_LIMIT) {
|
||||
/**
|
||||
* The number of probes is really high, rehash the map on the next insert.
|
||||
* Difficult to do now as rehash may throw an exception.
|
||||
@ -1376,10 +1379,6 @@ public:
|
||||
"MAXIMUM_MIN_LOAD_FACTOR should be < MINIMUM_MAX_LOAD_FACTOR");
|
||||
|
||||
private:
|
||||
static const distance_type REHASH_ON_HIGH_NB_PROBES__NPROBES = 128;
|
||||
static constexpr float REHASH_ON_HIGH_NB_PROBES__MIN_LOAD_FACTOR = 0.15f;
|
||||
|
||||
|
||||
/**
|
||||
* Return an always valid pointer to an static empty bucket_entry with last_bucket() == true.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user