Question: Create a function str_hash that takes a string str as an input parameter and returns its hash value. The hash value for this problem is

Create a function str_hash that takes a string str as an input parameter and returns its hash value. The hash value for this problem is defined by the following formula n 1 i = 0 s t r [ i ] 31 i , where str[i] corresponds to the ascii value of the character at index i. The following condition has to hold: if two strings are equal, then also their hashes have to be equal. Notice, the contrary doesnt have to hold, that is, if the hashes are equal then the strings do not necessarily have to be equal.

The function name and parameters are as following:

unsigned long long str_hash(const char *str);

must be typed in C++ and can only use #include and or

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!