unordered_set reserve() function in C++ STL
The unordered_set::reserve() method is a builtin function in C++ STL which is used to request capacity change of unordered_set. It sets the number of buckets in the container to contain at least n elements. If n is greater than the current bucket_count multiplied by the max_load_factor, the container’s bucket_count is increased and a rehash is forced. If n is lower than the bucket_count, then the function has no effect on it. Syntax:
Parameter: The function accepts a single mandatory parameter n which sets the number of buckets in the container (bucket_count) to the most appropriate to contain at least n elements. Return Value: This function doesn’t returns anything. Below programs illustrate the unordered_set::reserve() function: Program 1:
geeksforgeeks users geeks for
Time complexity: O(N)
Please Login to comment...