GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::unordered_set::load_factor - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. unordered_set
  3. unordered_set
  4. load_factor

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<unordered_set>

std::unordered_set::load_factor(C++11)

float load_factor() const noexcept;           // (1) C++11
constexpr float load_factor() const noexcept; // (1) C++26

概要

現在の負荷率(バケットあたりの要素数の平均)を取得する。

戻り値

現在の負荷率として、以下を返す:

size() / bucket_count()

例外

投げない。

計算量

定数。

例

#include <iostream>
#include <unordered_set>
#include <algorithm>
#include <iterator>

template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
  std::copy(c.begin(), c.end(), std::ostream_iterator<typename C::value_type>(os, ", "));
  os << "\nsize is " << c.size() << ", bucket_count is " << c.bucket_count() << ", load_factor is " << c.load_factor() << '\n' << std::endl;
}

int main()
{
  std::unordered_set<int> us{ 1, 3, 5, 7, 9, };

  print(us);

  us.insert({ 2, 4, 6, 8, 10, });

  print(us);
}

出力例

9, 7, 5, 3, 1,
size is 5, bucket_count is 5, load_factor is 1

10, 8, 6, 4, 2, 9, 7, 5, 3, 1,
size is 10, bucket_count is 11, load_factor is 0.909091

バージョン

言語

  • C++11

処理系

  • Clang: 3.1 ✅
  • GCC: 4.7.0 ✅
  • Visual C++: ?

関連項目

名前 説明
size 要素数の取得
bucket_count バケット数の取得
max_load_factor 負荷率の最大値を取得、設定
rehash 最小バケット数指定によるバケット数の調整
reserve 最小要素数指定によるバケット数の調整

参照

  • P3372R3 constexpr containers and adaptors
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.