Doubt regarding hashfunction

i am having a problem in understanding how you have declared the hash function, mainly in the datatype and use of ‘const’ keyword. Can you help me with it ?

@akshatsaraswat03 hey when overloading the == operator, we must make sure we do not change any data, so we make passed object a const, and func also const to prevent change in data members. Similary when overloading () here we again need to make sure we do not change data so we make it const

@akshatsaraswat03 when we are creating unordered_map for a custom class, we need to specify that how our comparison will be done and what is the key.
For specifying comparison we overload == operator, now we need to define what will be the key for custom class, for that we need to pass a functor as third argument unordered_map’s declaration.
in the given example class hashfn defines our key (by overloading () operator), now when will have 2 matching keys we will do comparison for that == is already overloaded.
If this resolves your doubt mark it as resolved.

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.