size_type bucket_size ( size_type n ) const;
// unordered_set::bucket_size #include <iostream> #include <string> #include <unordered_set> int main () { std::unordered_set<std::string> myset = { "red", "green", "blue", "yellow", "purple", "pink" }; unsigned nbuckets = myset.bucket_count(); std::cout << "myset has " << nbuckets << " buckets:\n"; for (unsigned i=0; i<nbuckets; ++i) { std::cout << "bucket #" << i << " has " << myset.bucket_size(i) << " elements.\n"; } return 0; } |
unordered_set::bucket_count | 返回存储桶的数量(公众成员函数) |
unordered_set::bucket | 定位元素的存储桶(公众成员函数) |
unordered_set::size | 返回容量(公众成员函数) |