Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 1 In a file hashing.s, do the following: Declare a struct type RASHCELL, which is used to contain data in a hashtable. A KUSHCELL

image text in transcribed
Step 1 In a file hashing.s, do the following: Declare a struct type RASHCELL, which is used to contain data in a hashtable. A KUSHCELL should contain two fields: a word field that is a string - it should be of type char so it's a pointer, not an allocated way - and a next field that is a pointer to s FASHCELL, so that HASHCELLS can be linked together in a list Declare a global variable hashtable, representing a hash table, which is an array of HASHCELL pointers. You should use define to define a constant SIZE to be 100 and declare hashtable to have size elements. Define a function hash_string which takes a string (a char*) as a parameter and returns an unsigned integer between 0 and are -1, by hashing the string. You are free to choose your own hash algorithm, but here is a simple one you can use: Define an unsigned integer variable hash and initialize it to 1. In a loop that iternt over cach character in the string, set haah equal to thash * 7) + c in each iteration of the loop, where e is the current character. Since a charis just an 8-bit number, so it's fine to do arithmetic on it. o Return the value of hash mod SIZE (where is the mod operator) Remember that you can recognize the end of a string by the terminating 0. The quality of the hash (ie, how evenly it distributes hash values between 0 and SIZE-1) isn't so important here . Define a function insert_hash_cell that takes a string gin, achar *) as a parameter and inserts the string into the hash table as follows: It calls hash_string on the string, signing the result of the hash to an unsigned integer variable index It creates a HASHCELL (using malloch that the word field of the cell points to the string. IMPORTANT. You will need to make a copy of the string by performing the following steps Using malloc again, allocate a block of memory large enough to hold the string (including the out the end. I sugesting the built-in stelen function, described at the bottom of this gament, which gives you the length of a string without the out the end (so you'll need to add 1). Set the word field of the cell to point to the new back of memory Copy the characters of the string into the new lock. Iggesting the stropy function, described at the bottom of this assignment It inserts the new cell into the linked list of cell pointed to by hashtableindex] However, if the word in the new cell ready exists in the Tinkedlist, do not in the sex call this prevent aplicate words from being inserted into the hash tableting the best function described below, to compare the strings to see if they we the same Define a function eithash tabia thout the clients of the hash table Specifically, in a loop, for each from the father out then " then on the same time all the words in the hashtableta) und the carriage return. This way, the list of words teach of the les printed on Step 1 In a file hashing.s, do the following: Declare a struct type RASHCELL, which is used to contain data in a hashtable. A KUSHCELL should contain two fields: a word field that is a string - it should be of type char so it's a pointer, not an allocated way - and a next field that is a pointer to s FASHCELL, so that HASHCELLS can be linked together in a list Declare a global variable hashtable, representing a hash table, which is an array of HASHCELL pointers. You should use define to define a constant SIZE to be 100 and declare hashtable to have size elements. Define a function hash_string which takes a string (a char*) as a parameter and returns an unsigned integer between 0 and are -1, by hashing the string. You are free to choose your own hash algorithm, but here is a simple one you can use: Define an unsigned integer variable hash and initialize it to 1. In a loop that iternt over cach character in the string, set haah equal to thash * 7) + c in each iteration of the loop, where e is the current character. Since a charis just an 8-bit number, so it's fine to do arithmetic on it. o Return the value of hash mod SIZE (where is the mod operator) Remember that you can recognize the end of a string by the terminating 0. The quality of the hash (ie, how evenly it distributes hash values between 0 and SIZE-1) isn't so important here . Define a function insert_hash_cell that takes a string gin, achar *) as a parameter and inserts the string into the hash table as follows: It calls hash_string on the string, signing the result of the hash to an unsigned integer variable index It creates a HASHCELL (using malloch that the word field of the cell points to the string. IMPORTANT. You will need to make a copy of the string by performing the following steps Using malloc again, allocate a block of memory large enough to hold the string (including the out the end. I sugesting the built-in stelen function, described at the bottom of this gament, which gives you the length of a string without the out the end (so you'll need to add 1). Set the word field of the cell to point to the new back of memory Copy the characters of the string into the new lock. Iggesting the stropy function, described at the bottom of this assignment It inserts the new cell into the linked list of cell pointed to by hashtableindex] However, if the word in the new cell ready exists in the Tinkedlist, do not in the sex call this prevent aplicate words from being inserted into the hash tableting the best function described below, to compare the strings to see if they we the same Define a function eithash tabia thout the clients of the hash table Specifically, in a loop, for each from the father out then " then on the same time all the words in the hashtableta) und the carriage return. This way, the list of words teach of the les printed on

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

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

Explain in detail the developing and developed economy of India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = X 52+7 - 1)(x+2) dx

Answered: 1 week ago

Question

What is gravity?

Answered: 1 week ago

Question

What is the Big Bang Theory?

Answered: 1 week ago

Question

Question What are the requirements for a SIMPLE 401(k) plan?

Answered: 1 week ago