I did not understand why we are overloading the == operator and also the size_t return type of HashFn.
About operator overloading
Hey @Senjuti256
When we use custom data type for key(such as user defined class etc),
we have to define functions to check equality of key(using == operator overloading).
== operator tells the hashmap whether key used is already there, or is it a new entry.
this is not called explicitly
this will be called when hash map will be created and when you find a value **when you write (cout<<student_map[s3]<<endl)**
It’s a type which is used to represent the size of objects in bytes and is therefore used as the return type by the sizeof operator. It is guaranteed to be big enough to contain the size of the biggest object the host system can handle. Basically the maximum permissible size is dependent on the compiler; if the compiler is 32 bit then it is simply a typedef(i.e., alias) for unsigned int but if the compiler is 64 bit then it would be a typedef for unsigned long long . The size_t data type is never negative.
Therefore many C library functions declare their arguments and return type as size_t
I did not understand about the size_t keyword. In the hash function we convert the key to integer to know it’s position in the hashtable. What is the purpose of returning the memory size in bytes?
You can use unsigned long long as return type instead of it ,its not mandatory to use that only .
size_t is an alias to unsigned long long
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.