| 1534 | } |
| 1535 | |
| 1536 | void rehash_impl(size_type bucket_count) { |
| 1537 | GrowthPolicy new_growth_policy(bucket_count); |
| 1538 | if (bucket_count == this->bucket_count()) { |
| 1539 | return; |
| 1540 | } |
| 1541 | |
| 1542 | if (should_clear_old_erased_values( |
| 1543 | REHASH_CLEAR_OLD_ERASED_VALUE_THRESHOLD)) { |
| 1544 | clear_old_erased_values(); |
| 1545 | } |
| 1546 | |
| 1547 | std::vector<std::size_t> required_size_for_bucket(bucket_count, 0); |
| 1548 | std::vector<std::size_t> bucket_for_ivalue(size(), 0); |
| 1549 | |
| 1550 | std::size_t ivalue = 0; |
| 1551 | for (auto it = begin(); it != end(); ++it) { |
| 1552 | const std::size_t hash = hash_key(it.key(), it.key_size()); |
| 1553 | const std::size_t ibucket = new_growth_policy.bucket_for_hash(hash); |
| 1554 | |
| 1555 | bucket_for_ivalue[ivalue] = ibucket; |
| 1556 | required_size_for_bucket[ibucket] += |
| 1557 | array_bucket::entry_required_bytes(it.key_size()); |
| 1558 | ivalue++; |
| 1559 | } |
| 1560 | |
| 1561 | std::vector<array_bucket> new_buckets; |
| 1562 | new_buckets.reserve(bucket_count); |
| 1563 | for (std::size_t ibucket = 0; ibucket < bucket_count; ibucket++) { |
| 1564 | new_buckets.emplace_back(required_size_for_bucket[ibucket]); |
| 1565 | } |
| 1566 | |
| 1567 | ivalue = 0; |
| 1568 | for (auto it = begin(); it != end(); ++it) { |
| 1569 | const std::size_t ibucket = bucket_for_ivalue[ivalue]; |
| 1570 | append_iterator_in_reserved_bucket_no_check(new_buckets[ibucket], it); |
| 1571 | |
| 1572 | ivalue++; |
| 1573 | } |
| 1574 | |
| 1575 | using std::swap; |
| 1576 | swap(static_cast<GrowthPolicy&>(*this), new_growth_policy); |
| 1577 | |
| 1578 | m_buckets_data.swap(new_buckets); |
| 1579 | m_buckets = !m_buckets_data.empty() ? m_buckets_data.data() |
| 1580 | : static_empty_bucket_ptr(); |
| 1581 | |
| 1582 | // Call max_load_factor to change m_load_threshold |
| 1583 | max_load_factor(m_max_load_factor); |
| 1584 | } |
| 1585 | |
| 1586 | template <class U = T, typename std::enable_if< |
| 1587 | !has_mapped_type<U>::value>::type* = nullptr> |
nothing calls this directly
no test coverage detected