Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, can someone please explain this code to me line by line please? Thank you. Also if possible show sample output. unsigned long hashDJB2(char *str)

Hello, can someone please explain this code to me line by line please? Thank you. Also if possible show sample output.

unsigned long hashDJB2(char *str)

{

unsigned long hash = 5381;

int c;

while ((c = *str++))

hash = ((hash << 5) + hash) + c; /* hash * 33 + c */

return hash;

}

unsigned long hashKR(char *str)

{

unsigned int hash = 0;

int c;

while ((c = *str++))

hash += c;

return hash;

}

int main(int argc, char *argv[])

{

char *buffer;

int bufferlen = MAXSTRING;

unsigned long newHash;

unsigned long newKRhash;

buffer = malloc(MAXSTRING);

if (buffer == NULL)

{

printf("Bad malloc bye! ");

return 1;

}

while (fgets(buffer, bufferlen, stdin))

{

// printf("data in:%s", buffer);

if (ferror(stdin))

{

printf("Error on stdin ");

break;

}

/*

* Hash 'em up - commences!

*/

newHash = hashDJB2(buffer);

newKRhash = hashKR(buffer);

printf("hash:%016lx:%016lx:%s", newHash, newKRhash, buffer);

}

printf(" Done! ");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

In what way does technology help QB House to keep its costs down?

Answered: 1 week ago

Question

Define analytics and business analytics.

Answered: 1 week ago