Skip to main content

std::unordered_map bucket() method

// Const version only
size_type bucket( const Key& key ) const;

Returns the index of the bucket for key key. Elements (if any) with keys equivalent to key are always found in this bucket. The returned value is valid only for instances of the container for which bucket_count() returns the same value.

danger

The behavior is undefined if bucket_count() is zero.

Parameters

  • key - the value of the key to examine

Return value

Bucket index for the key key.

Complexity

Constant - O(1).

Exceptions

(none)

Examples

important

This section requires improvement. You can help by editing this doc page.

This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.

std::unordered_map bucket() method

// Const version only
size_type bucket( const Key& key ) const;

Returns the index of the bucket for key key. Elements (if any) with keys equivalent to key are always found in this bucket. The returned value is valid only for instances of the container for which bucket_count() returns the same value.

danger

The behavior is undefined if bucket_count() is zero.

Parameters

  • key - the value of the key to examine

Return value

Bucket index for the key key.

Complexity

Constant - O(1).

Exceptions

(none)

Examples

important

This section requires improvement. You can help by editing this doc page.

This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.