SWEN-250  – Personal Software Engineering

Hashmap Activity

 

Problem

 

This activity requires you to write a C function that deletes a symbol / value pair from a hashmap. The prototype (signature) of the function is

 

void drop( char *symbol )

 

The given code hashmap.c includes the following functions:

 

insert( )  - inserts a symbol / value pair into the hashmap using symbol as the key

hash( )  uses the given symbol to perform a hash function which computes the index (bin) into the hash table

lookup( ) – returns the hash table bin entry (symbol / value) for a given symbol

dump( )  - print all the symbol / value pairs for the hash table

main( ) – edit this function to include any tests you created to verify your solution.

 

The following standard string functions are also used:

int strcmp( char *s1, char *s2 ) – compares two strings, returns zero if  strings are equal

char *strdup ( char *s1 ) – returns an allocated block of memory containing a duplicate of  string s1

 

  1. Download (right-click, Save as) the code and makefile:
  2. READ the existing code before you begin writing the drop() function. Draw diagrams as needed to (re)familiarize your self with the hashmap data structure.
  3. Write the drop() function.
  4. Sample test cases are included in main(). The output of these tests is captured in results.txt. Your solution is correct when there are no differences between your output and the results.txt file.
  5. You do not need to modify any existing functions other than drop().


NOTE: In writing drop(), it is your responsibility to ensure that all the allocated memory resources/areas are no longer needed in the hash map are properly released in the proper order.