CS302 -- Lab 7

Extendible Hashing


Lab Objective

This lab is designed to give you experience with:

  1. external searching via extendible hashing,
  2. file systems, and
  3. bit shifting

  • To begin, read the Documentation for the disk package.

    Overview

    In this lab you will implement a program that reads entries from a roster file and inserts them into an extendible hash table. Your program will then request last names from the user and print out all roster entries with that last name.

    A sample entry from the roster might look as follows:

    Riggs       Gerald    6.0  TB Sr Tennessee Chattanooga, TN     
    
    You will notice that there are seven fields representing the following items:
    1. last name (12 chars)
    2. first name (10 chars)
    3. height (5 chars)
    4. position (3 chars)
    5. rank (3 chars)
    6. team (10 chars)
    7. home town (20 chars)

    You may make the following assumptions:

    1. no players have the same first and last name.
    2. first and last names are single words.
    3. the code provided to you will read the roster file and store it into a Roster_Record class object. Look at the class declaration for Roster_Record in hsearch.h. You will notice that the class declaration gives you methods for creating a Roster_Record, printing a Roster_Record, and accessing the fields in a Roster_Record. You will also notice that the hsearch.cpp file contains code for reading the records from a file.

    Sample binary code is available as /home/parker/courses/cs302/lab7/hsearch. You can run this program as follows:

     hsearch roster 
    
    to see how the program should run. Here is a brief sample program output:
    Enter last name (Ctrl-D to exit): Wilson 
    
    Ellix Wilson 5.10 LB So Tennessee Memphis, TN
    Nick Wilson 6.2 LB Sr Tennessee Knoxville, TN
    
    Enter last name (Ctrl-D to exit): Manning
    
    Peyton Manning 6.5 QB 18 Colts New Orleans, LA
    Eli Manning 6.4 QB 10 Giants New Orleans, LA
    
    Enter last name (Ctrl-D to exit): Haralson
    
    Parys Haralson 6.2 DE Sr Tennessee Flora, MS
    
    Enter last name (Ctrl-D to exit): Jones
    
    Couldn't find Jones in the roster
    
    Enter last name (Ctrl-D to exit): ^D
    

    Details

    Implement an extendible hashing scheme that:

    1. reads in the roster file and uses extendible hashing to store the roster file on the simulated disks provided by the disks package, and

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

    To assist you in getting started, we have provided you with an include file, /home/parker/courses/cs302/labs/lab7/hsearch.h, and some initial code, /home/parker/courses/cs302/labs/lab7/hsearch.cpp. You can complete this lab by editing hsearch.cpp in the following manner:

    1. Write the function split_rec_node. Peruse the hsearch.cpp file to figure out what this function should do.

    2. Write the function search. Peruse the hsearch.cpp file to figure out what this function should do.

    3. Write the code to insert the records in the roster file into the extendible hash table.

    4. Write the code to search for records requested by the user.


    Information that May Prove Helpful

    1. To simplify this lab, keep the index for the extendible hash table in main memory rather than on disk. The data structure will be an array of pointers to index records. You will start with an index of two entries and double it as necessary.

    2. In each record page, records are stored in alphabetical order by last name.

    3. You can find disk.h in /home/parker/courses/cs302/include and disk.o in /home/parker/courses/cs302/objs. If you want to try to run on your home computer you can find the code for disk.cpp in /home/parker/courses/cs302/src/disk.cpp.

    4. Disks have the following parameters:

      • Each disk contains a maximum of 4 pages.
      • Each record page contains a maximum of 5 records.


    Helpful Functions for Your Lab

    To simplify the lab somewhat, a number of functions have been provided for you:


    What to Submit

    1. A makefile
    2. roster
    3. hsearch.cpp
    4. hsearch.h
    5. README (optional): If you cannot complete the lab then submit a README file that tells the TAs what you were able to accomplish. If possible include some debugging statements that shows what happens as you insert records into the hash key. Appropriate debugging information would be a statement telling the user which roster entry is being inserted, what the page looks like once the roster entry is inserted, and what the index looks like after each insertion.