How to find the size of the hash table?

I have a hash table defined as

typedef std::unordered_map<unsigned long long int,unsigned long long int> table_map;

and in the program I read the contents of the file into the buffer using fread similar to this:

fread(buffer, sizeof(long long int), 1024, file1);

Declare a hash table as

table_map c1;

Now I create a hash table like

for (i = 0; i < 1024; i++)
    c1.insert(table_map::value_type(buffer[i], i));

Now my questions, after the for loop, how can I get the size of the hash table?

It has 1024 elements of type unsigned long long int, as well as keys of the same type, but I could not use sizeof(Mymap)either `size of (c1) beacause, just returning the value 32. Is there a way to find this?

Thanks Sunil

+3
source share
2 answers

Multiply the container size property by the size of the pair:

std::cout << c1.size() * sizeof(table_map::value_type) << "\n";

On my system, this prints:

16384

, . , ( ) .

, .:: bucket,:: bucket_count,:: bucket_size. , . .

+4

- size(), .

c1.size().

+3

Source: https://habr.com/ru/post/1761424/


All Articles