unordered_set bucket_size() in C++ STL
The unordered_set::bucket_size() function is a built-in function in C++ STL which returns the total number of elements present in a specific bucket in an unordered_set container.
The bucket is a slot in the unordered_set’s internal hash table where elements are stored.
Note: Buckets in unordered_set are numbered from 0 to n-1, where n is the total number of buckets.
Parameter: This function accepts a single parameter n which is mandatory. This parameter represents the bucket number for which it is needed to find the total number of elements.
Return Value: This function returns the total number of elements present in the bucket n.
Below programs illustrate the unordered_set::bucket_size() function:
sampleSet has 7 buckets Bucket number 3 contains 1 elements
sampleSet has 7 buckets Bucket number 0 contains 0 elements