Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Delete symbol/ val entry in bottom method define BINSIZE 11 *number of hashmap bins (intentionally small to create collisions) */ struct binEntry struct binEntry *next;
Delete symbol/ val entry in bottom method
define BINSIZE 11 *number of hashmap bins (intentionally small to create collisions) */ struct binEntry struct binEntry *next; next entry in the list / struct binEntry *prev previous entry in the list char *symbol; char *value; /* defined symbol name / value of the symbol/ static struct binEntry *hashtable[BINSIZE; /* table of binEntry pointers /* this array is visible to all functions in this file hash - Create an unsigned integer hashvalue for a string DO NOT EDIT THIS FUNCTION) unsigned int hash char *s) unsigned int hashvalue; for ( hashvalue= 0; *s !- "10' ; s++) return hashvalue % BINS IZE; hashvalue 31 *hashvalue; lookup - Given a symbol name, return a binEntry. Return NULL if not found DO NOT EDIT THIS FUNCTION) struct binEntry lookup( char *symbol) struct binEntry *entry; for entry hashtable[ hash (symbol)]; entry-NULLentry-entry->next) if strcmp symbol, entry->symbol) -- 0) return entry return NULL insert -Inserts a symbol/value pair into the hashmap. Existing symbols are updated with the new value. A pointer to the new entry is returned. DO NOT EDIT THIS FUNCTION) struct binEntry *insert( char *symbol, char *value) struct binEntry *entry; unsigned int hashvalue; (( entry-lookup(symbo1))NULL ) ( symbol not found, create new entry * entry - (struct binEntry*) malloc( sizeof (struct binEntry) entry->symbol strdup symbol); hashvalue-hash( symbol ); entry->next - hashtable[hashvalue]; /* new entries become the start of the chain * entry->prev = NULL; if ( entry->next != NULL ) /* create a duplicate of this symbol /*a NULL previous pointer means it is first on the list*/ /*if there is an existing entry in this bin, set its prev pointer */ (entry->next)-preventry; /* this entry becomes the head of the list for this bin / /*symbol exists, just update value/ /* release memory for current value being replaced */ hashtable[hashvalue] entry: elsef free( (void*) entry->value) entry->valuestrdup value) /*create a duplicate of the value for this entry */ return entry, drop - Deletes a symbol/value entry from the hashmap. Delete request is ignored if the symbol is not found void drop( char *symbol ) /YOUR CODE GOES HERE returni define BINSIZE 11 *number of hashmap bins (intentionally small to create collisions) */ struct binEntry struct binEntry *next; next entry in the list / struct binEntry *prev previous entry in the list char *symbol; char *value; /* defined symbol name / value of the symbol/ static struct binEntry *hashtable[BINSIZE; /* table of binEntry pointers /* this array is visible to all functions in this file hash - Create an unsigned integer hashvalue for a string DO NOT EDIT THIS FUNCTION) unsigned int hash char *s) unsigned int hashvalue; for ( hashvalue= 0; *s !- "10' ; s++) return hashvalue % BINS IZE; hashvalue 31 *hashvalue; lookup - Given a symbol name, return a binEntry. Return NULL if not found DO NOT EDIT THIS FUNCTION) struct binEntry lookup( char *symbol) struct binEntry *entry; for entry hashtable[ hash (symbol)]; entry-NULLentry-entry->next) if strcmp symbol, entry->symbol) -- 0) return entry return NULL insert -Inserts a symbol/value pair into the hashmap. Existing symbols are updated with the new value. A pointer to the new entry is returned. DO NOT EDIT THIS FUNCTION) struct binEntry *insert( char *symbol, char *value) struct binEntry *entry; unsigned int hashvalue; (( entry-lookup(symbo1))NULL ) ( symbol not found, create new entry * entry - (struct binEntry*) malloc( sizeof (struct binEntry) entry->symbol strdup symbol); hashvalue-hash( symbol ); entry->next - hashtable[hashvalue]; /* new entries become the start of the chain * entry->prev = NULL; if ( entry->next != NULL ) /* create a duplicate of this symbol /*a NULL previous pointer means it is first on the list*/ /*if there is an existing entry in this bin, set its prev pointer */ (entry->next)-preventry; /* this entry becomes the head of the list for this bin / /*symbol exists, just update value/ /* release memory for current value being replaced */ hashtable[hashvalue] entry: elsef free( (void*) entry->value) entry->valuestrdup value) /*create a duplicate of the value for this entry */ return entry, drop - Deletes a symbol/value entry from the hashmap. Delete request is ignored if the symbol is not found void drop( char *symbol ) /YOUR CODE GOES HERE returniStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started