CS 2420-20 Homework 10

Due: Tuesday, February 21st, 2012 9:10am

Part 1 – Hashing Snakes

Use hash.c and hash.h from hashtable.zip. You will not need to modify them for this part, and you don’t need to hand them in.

Represent a snake as a pointer to a snake structure type:

  typedef struct snake {
    char* name;
    double weight;
    char* food;
  } snake;

Implement comparison and hashing functions on snakes, where two snake structures represent the same snake if they have exactly the same name, weight, and favorite food.

Write tests that put and retrieve snakes in a hash table. The value to which each snake is mapped doesn’t matter; that is, the hash table acts as a “set” data structure to keep track of an unordered set of snakes.

Submit your work as snake.c.

Part 2 – Double Hashing

Convert hash.c and hash.h from linear hashing to double hashing, calling the new versions hash2.c and hash2.h. Make a snake2.c variant of snake.c that supplies the necessary two hash functions for snake structures.

Submit your work as hash2.c, hash2.h, and snake2.c.


Last update: Wednesday, February 15th, 2012
mflatt@cs.utah.edu