unordered_map max_size in C++ STL
Last Updated :
14 Dec, 2018
The unordered_map::max_size is a built in function in C++ STL. It returns maximum number of elements which unordered_map can hold. Maximum number of elements in any container depends upon system and library implementation.
Syntax
size unordered_map.max_size()
Parameters: It does not accept any parameters.
Return type: Unsigned integer a container can hold maximum elements.
Example 1
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map< int , int > sample;
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
sample.insert({ 1, 10 });
sample.insert({ 2, 10 });
sample.insert({ 3, 10 });
sample.insert({ 4, 10 });
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
return 0;
}
|
Output:
Current size is : 0
max size is : 1152921504606846975
Current size is : 4
max size is : 1152921504606846975
Example 2
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map< char , int > sample;
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
sample.insert({ 'a' , 10 });
sample.insert({ 'b' , 10 });
sample.insert({ 'c' , 10 });
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
return 0;
}
|
Output:
Current size is : 0
max size is : 1152921504606846975
Current size is : 3
max size is : 1152921504606846975
Complexity : Its complexity is constant.
Share your thoughts in the comments
Please Login to comment...