C++ STL-এ unordered_multimap reserve() ফাংশন কন্টেইনারে থাকা বালতির সংখ্যাকে সবচেয়ে উপযুক্ত সংখ্যায় সেট করে যাতে এতে অন্তত n উপাদান থাকে।
n, max_load_factor দ্বারা গুণিত বাকেটের বর্তমান সংখ্যার থেকে বেশি হলে, কন্টেইনারের বালতির সংখ্যা বৃদ্ধি করা হয় এবং একটি রিহ্যাশ বাধ্য করা হয়৷
রিজার্ভ () কিছুই ফেরত দেয় না এবং n কে একটি প্যারামিটার হিসাবে গ্রহণ করে যা অনুরোধকৃত ন্যূনতম ক্ষমতা অনুসারে উপাদানগুলির ন্যূনতম সংখ্যা নির্দিষ্ট করে৷
অ্যালগরিদম
Begin Declare the vector m. m.reserve(6) = the size is reserved for the bucket to contain minimum number of one elements. Insert the key value pairs. Print the result. End.
উদাহরণ কোড
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<char, int> m; //declaring m as map container
m.reserve(6);//restricting the most appropriate value of
m.insert (pair<char, int>('b', 10)); // inserting values
m.insert (pair<char, int>('a', 20));
cout << "The size is: " << m.size();
cout << "\nKey and values are: ";
for (auto it = m.begin(); it != m.end(); it++) {
cout << "{" << it->first << ", " << it->second << "} "; //printing the values of map container
}
return 0;
} আউটপুট
The size is: 2
Key and values are: {a, 20} {b, 10}