@@ -33,27 +33,26 @@ This method does not return a value (`void`).
3333
3434## Example
3535
36- This example demonstrates using ` . rehash()` to change the bucket count of an ` unordered_set ` :
36+ This example demonstrates using ` rehash() ` to change the bucket count of an ` unordered_set ` :
3737
3838``` cpp
3939#include < iostream>
4040#include < unordered_set>
41- using namespace std ;
4241
4342int main () {
44- unordered_set<int > numbers = {10, 20, 30, 40, 50};
43+ std:: unordered_set<int > numbers = {10, 20, 30, 40, 50};
4544
46- cout << "Initial bucket count: " << numbers.bucket_count() << endl ;
47- cout << "Number of elements: " << numbers.size() << endl ;
48- cout << "Load factor: " << numbers.load_factor() << endl ;
45+ std:: cout << "Initial bucket count: " << numbers.bucket_count() << "\n" ;
46+ std:: cout << "Number of elements: " << numbers.size() << "\n" ;
47+ std:: cout << "Load factor: " << numbers.load_factor() << "\n" ;
4948
5049 // Increase the number of buckets
5150 numbers.rehash(20);
5251
53- cout << "\nAfter rehash(20):" << endl ;
54- cout << "New bucket count: " << numbers.bucket_count() << endl ;
55- cout << "Number of elements: " << numbers.size() << endl ;
56- cout << "Load factor: " << numbers.load_factor() << endl ;
52+ std:: cout << "\nAfter rehash(20):\n" ;
53+ std:: cout << "New bucket count: " << numbers.bucket_count() << "\n" ;
54+ std:: cout << "Number of elements: " << numbers.size() << "\n" ;
55+ std:: cout << "Load factor: " << numbers.load_factor() << "\n" ;
5756
5857 return 0;
5958}
@@ -76,32 +75,32 @@ Load factor: 0.217391
7675
7776## Codebyte Example
7877
79- In this example, the code demonstrates how ` . rehash()` can be used to optimize an ` unordered_set ` before inserting a large number of elements, reducing the need for automatic rehashing:
78+ In this example, the code demonstrates how ` rehash() ` can be used to optimize an ` unordered_set ` before inserting a large number of elements, reducing the need for automatic rehashing:
8079
8180``` codebyte/cpp
8281#include <iostream>
8382#include <unordered_set>
84- using namespace std;
83+ #include <string>
8584
8685int main() {
87- unordered_set<string> words;
86+ std:: unordered_set<std:: string> words;
8887
89- cout << "Initial bucket count: " << words.bucket_count() << endl ;
88+ std:: cout << "Initial bucket count: " << words.bucket_count() << "\n" ;
9089
9190 // Pre-allocate buckets for expected elements
9291 words.rehash(100);
9392
94- cout << "Bucket count after rehash(100): " << words.bucket_count() << endl ;
93+ std:: cout << "Bucket count after rehash(100): " << words.bucket_count() << "\n" ;
9594
9695 // Insert elements
9796 words.insert("apple");
9897 words.insert("banana");
9998 words.insert("cherry");
10099 words.insert("date");
101100
102- cout << "Bucket count after insertions: " << words.bucket_count() << endl ;
103- cout << "Current load factor: " << words.load_factor() << endl ;
104- cout << "Max load factor: " << words.max_load_factor() << endl ;
101+ std:: cout << "Bucket count after insertions: " << words.bucket_count() << "\n" ;
102+ std:: cout << "Current load factor: " << words.load_factor() << "\n" ;
103+ std:: cout << "Max load factor: " << words.max_load_factor() << "\n" ;
105104
106105 return 0;
107106}
0 commit comments