From f2fa12e76d947840289a5110107adaf1500ad122 Mon Sep 17 00:00:00 2001 From: fawez9 Date: Sat, 13 Dec 2025 13:15:39 +0100 Subject: [PATCH 1/2] docs: C++ Unordered-sets: max_bucket_count() (#8077) --- .../max-bucket-count/max-bucket-count.md | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md diff --git a/content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md b/content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md new file mode 100644 index 00000000000..5a7de627a26 --- /dev/null +++ b/content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md @@ -0,0 +1,89 @@ +--- +Title: "max_bucket_count()" +Description: "Returns the maximum number of buckets that the unordered set can have." +Subjects: + - "Code Foundations" + - "Computer Science" +Tags: + - "Methods" + - "Sets" + - "Hash Tables" + - "STL" +CatalogContent: + - "learn-c-plus-plus" + - "paths/computer-science" +--- + +The **`max_bucket_count()`** method returns the maximum number of buckets that an [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set) container can have. This value represents a theoretical upper limit imposed by the system or library implementation, not the current number of buckets in use. The actual number of buckets used by the container is typically much smaller and can be queried using `bucket_count()`. + +## Syntax + +```pseudo +unordered_set_name.max_bucket_count(); +``` + +**Return value:** + +Returns a `size_type` value representing the maximum possible number of buckets the container could theoretically hold. This is a system-dependent constant that is typically a very large number. + +## Example + +This example demonstrates obtaining the maximum bucket count and comparing it with the current bucket count: + +```cpp +#include +#include +using namespace std; + +int main() { + unordered_set numbers = {10, 20, 30, 40, 50}; + + cout << "Maximum bucket count: " << numbers.max_bucket_count() << "\n"; + cout << "Current bucket count: " << numbers.bucket_count() << "\n"; + cout << "Number of elements: " << numbers.size() << "\n"; + + return 0; +} +``` + +A sample output of this code is: + +```shell +Maximum bucket count: 576460752303423487 +Current bucket count: 7 +Number of elements: 5 +``` + +> **Note:** The exact maximum bucket count value may vary depending on the system architecture and compiler implementation. + +## Codebyte Example + +In this example, the code demonstrates how the maximum bucket count remains constant while the current bucket count can change as elements are added: + +```codebyte/cpp +#include +#include +#include +using namespace std; + +int main() { + unordered_set fruits = {"apple", "banana", "cherry"}; + + cout << "Initial state:\n"; + cout << "Max bucket count: " << fruits.max_bucket_count() << "\n"; + cout << "Current bucket count: " << fruits.bucket_count() << "\n"; + cout << "Current size: " << fruits.size() << "\n"; + + // Add more elements + fruits.insert("date"); + fruits.insert("elderberry"); + fruits.insert("fig"); + + cout << "\nAfter adding more elements:\n"; + cout << "Max bucket count: " << fruits.max_bucket_count() << "\n"; + cout << "Current bucket count: " << fruits.bucket_count() << "\n"; + cout << "Current size: " << fruits.size() << "\n"; + + return 0; +} +``` From a3c862f551856f2c4f2246f91e779a0920743bae Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 15 Dec 2025 16:52:55 +0530 Subject: [PATCH 2/2] Refactor max-bucket-count.md formatting and content Updated formatting and descriptions in max-bucket-count.md. --- .../max-bucket-count/max-bucket-count.md | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md b/content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md index 5a7de627a26..7215d54c4bc 100644 --- a/content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md +++ b/content/cpp/concepts/unordered-set/terms/max-bucket-count/max-bucket-count.md @@ -1,17 +1,16 @@ --- -Title: "max_bucket_count()" -Description: "Returns the maximum number of buckets that the unordered set can have." +Title: 'max_bucket_count()' +Description: 'Returns the maximum number of buckets that the unordered_set can have.' Subjects: - - "Code Foundations" - - "Computer Science" + - 'Code Foundations' + - 'Computer Science' Tags: - - "Methods" - - "Sets" - - "Hash Tables" - - "STL" + - 'Methods' + - 'Sets' + - 'STL' CatalogContent: - - "learn-c-plus-plus" - - "paths/computer-science" + - 'learn-c-plus-plus' + - 'paths/computer-science' --- The **`max_bucket_count()`** method returns the maximum number of buckets that an [`unordered_set`](https://www.codecademy.com/resources/docs/cpp/unordered-set) container can have. This value represents a theoretical upper limit imposed by the system or library implementation, not the current number of buckets in use. The actual number of buckets used by the container is typically much smaller and can be queried using `bucket_count()`. @@ -22,9 +21,13 @@ The **`max_bucket_count()`** method returns the maximum number of buckets that a unordered_set_name.max_bucket_count(); ``` +**Parameters:** + +This method takes no parameters. + **Return value:** -Returns a `size_type` value representing the maximum possible number of buckets the container could theoretically hold. This is a system-dependent constant that is typically a very large number. +Returns a `size_type` value representing the maximum possible number of buckets the container could theoretically hold. This is an implementation-defined limit that is typically a very large number. ## Example