CSC161 2010F Imperative Problem Solving

Assignment 9: Hash Tables

Assigned: Friday, 19 November 2010
Due: 11:00 p.m., Wednesday, 24 November 2010

This assignment is also available in PDF.

Summary: In this assignment, you will extend our implementation of hash tables.

Purposes: To give you more experience with pointers and structures.

Expected Time: Three to four hours.

Collaboration: I encourage you to work in groups of two or three students. However, you may work on your own or in groups of up to size four. You may discuss the assignment with anyone you wish, provided you clearly document such discussions.

Submitting: Email me a tarball of your important files (your .c files, your .h files, your Makefile, a typescript of a sample session, and anything else you deem appropriate).

Warning: So that this assignment is a learning experience for everyone, I may spend class time publicly critiquing your work.


In class, we developed a simple implementation of hash tables, based on the code in K&R. In particular, we

We now have a limited hash table library. But many clients will want a richer library, one with more functions. In this assignment, you will add functions.


Add the following functions to the hash table implementation and update the two test programs to work with them.

int contains_key (struct hash *hashtab, char *key)
Determine if hashtab has an entry with key key.
char *find_key (struct hash *hashtab, char *value)
Given a value, find a key that maps to that value. If no such key exists, return NULL.
void delete (struct hash *hashtab, char *key)
Given a key, remove the associated key/value pair from the hash table. If the key/value pair is not in the hash table, do nothing.
void iterate (struct hash *hashtab, void (*fun)(char *key, char *value))
Call fun on every key/value pair in the hash table.
void free_hash (struct hash *hashtab)
Free all of the memory associated with hashtab.



Thursday, 18 November 2010 [Samuel A. Rebelsky]

  • Designed.

Friday, 19 November 2010 [Samuel A. Rebelsky]


Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Fri Nov 19 09:08:55 2010.
The source to the document was last modified on Fri Nov 19 09:08:49 2010.
This document may be found at

Samuel A. Rebelsky,