CS302 -- Lab 8


Lab Objective

This lab is designed to give you experience with:

  1. external searching,
  2. hashing, and
  3. bit manipulation.


Setting Up

You should copy the following files from the /ruby/homes/ftp/pub/bvz/classes/cs302/labs/lab8 directory to your directory:

Note that we have provided a partial makefile for you. You will need to add the appropriate command to compile your .cc files.

In order to make the graphics package work, you will need to type the following two commands in every window in which you run your program (or you can place them in your .cshrc file):

setenv AMULET_DIR /sunshine/homes/bvz/amulet/amulet3/
setenv AMULET_VARS_FILE Makefile.vars.gcc.Solaris
If you have certain types of protections, you may also get a message saying that your display could not be opened when you run your program. If this happens, type the following command:
xhost +machine_name
where machine_name is the name of your machine (e.g., cetus4a).


Problem Statement

In this lab you will implement the extendible hashing algorithm presented in class. In particular, you will implement an extendible hashing scheme that:

  1. reads in the roster file from lab 4 and use extendible hashing to store the roster file, and

  2. allows searches on the hashed file using last names. Your program should print out all roster entries with the given last name.

A working version of the program is in the directory /ruby/homes/ftp/pub/bvz/classes/cs302/bin/extendHash (the visual debugging environment is not yet included with that program but soon will be). If you have a question about what your program should do, first see what this program does (note: you must execute extendHash from a directory that includes the file roster; otherwise you will receive the error message "roster not found").


Format of the Input

The format for the roster file is described in lab4.


Format of the Output

Once your program has stored the roster file in an extendible hash table, it should allow the user to start querying the roster file by printing the following prompt:

Enter last name (Ctrl-D to exit): 

It should then take the last name that is provided and either print out all records with that last name or print a message that the name cannot be found in the roster. For example:

Enter last name (Ctrl-D to exit): Rosener
Couldn't find Rosener in the roster

Enter last name (Ctrl-D to exit): Colquitt
Colquitt    Jerry       6.4     QB  Sr  Tennessee   Oak Ridge, TN

Enter last name (Ctrl-D to exit): Bryson
Couldn't find Bryson in the roster

Enter last name (Ctrl-D to exit): Smith
Smith       Jeff        6.3     OG  Jr  Tennessee   Decatur, TN
Smith       James       6.0     DB  Jr  Tennessee   Blythe, CA

Your program should keep printing the prompt message until the user types Ctrl-D, at which point the program should exit.


The ExtendibleHashTable Class

You should write an ExtendibleHashTable class that implements an extendible hash table data structure. The public interface for the class should look as follows:

class ExtendibleHashTable {
  public:
    ExtendibleHashTable();
    void insert(Record *rec);
    Dlist<Record *> find(string name);
};

You may also want to add additional protected methods to assist with the implementation of these public methods. The design of the ExtendibleHashTable class is further described here (toward the bottom of the document).


Classes For This Lab

In order to assist you with this lab we have prepared a visual debugging environment that shows your extendible hash table and buckets and that allows you to pause your program and inspect these data structures. The visual debugger is written as a driver program that initializes the environment and then calls your searching function. Hence for this lab you will not write a main function. Instead you will write a function named extendHashTable and this function will be called by our driver program (named driver.cc). extendHashTable takes no arguments. The name of the roster file should be hardcoded as a constant string. The declaration for your extendHashTable function should look as follows:

void extendHashTable();

You will also need to use the classes that we have provided in order to make the visual debugging environment work. a list of these classes and the methods they support: You can find documentation for these classes and an explanation of how to make the visual debugger pause here.


Information You Need To Know

  1. You should use a bucket size of 5.

  2. As in lab 7 you will not use the actual Unix file system to store the extendible hash table. Instead you will use the classes we have provided to construct and store the hash table.

  3. Unlike in lab 7 you will have to use the Fields package to read records from the roster file into memory. The roster file is the same one you used in lab 4, so you should be able to reuse your code from lab 4 to read the roster file and to break each record into the appropriate fields.


What to Submit

Using the standard electronic submit procedure, you should email your makefile and source files (both .h and .cc files) to Hui. The name of the executable binary file created by your makefile should be extendHash.