Libreria C ++ Unordered_set - bucket_size

Descrizione

Restituisce il numero di elementi nel bucket n.

Dichiarazione

Di seguito è riportata la dichiarazione per std :: unordered_set :: bucket_size.

C ++ 11

size_type bucket_size ( size_type n ) const;

Parametri

n - Contiene informazioni sul numero di bucket.

Valore di ritorno

Restituisce il numero di elementi nel bucket n.

Eccezioni

L'eccezione viene generata se un qualsiasi oggetto di confronto degli elementi genera un'eccezione.

Tieni presente che gli argomenti non validi causano un comportamento indefinito.

Complessità temporale

tempo costante.

Esempio

L'esempio seguente mostra l'utilizzo di std :: unordered_set :: bucket_size.

#include <iostream>
#include <string>
#include <unordered_set>

int main () {
   std::unordered_set<std::string> myset =
      { "sai", "ram", "krishna", "prasad", "tutorials", "point" };

   unsigned nbuckets = myset.bucket_count();

   std::cout << "myset has " << nbuckets << " buckets:\n";

   for (unsigned i = 0; i < nbuckets; ++i) {
      std::cout << "bucket #" << i << " has " << myset.bucket_size(i) << " elements.\n";
   }

   return 0;
}

Compiliamo ed eseguiamo il programma sopra, questo produrrà il seguente risultato:

myset has 7 buckets:
bucket #0 has 1 elements.
bucket #1 has 1 elements.
bucket #2 has 0 elements.
bucket #3 has 0 elements.
bucket #4 has 2 elements.
bucket #5 has 1 elements.
bucket #6 has 1 elements.