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:
- last name (12 chars)
- first name (10 chars)
- height (5 chars)
- position (3 chars)
- rank (3 chars)
- team (10 chars)
- home town (20 chars)
You may make the following assumptions:
- no players have the same first and last name.
- first and last names are single words.
- 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:
- reads in the roster file and uses extendible hashing to store the
roster file on the simulated disks provided by the disks package, and
- 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:
- Write the function split_rec_node.
Peruse the hsearch.cpp file to figure
out what this function should do.
- Write the function search.
Peruse the hsearch.cpp file to figure out
what this function should do.
- Write the code to insert the records in the roster file into the
extendible hash table.
- Write the code to search for records requested by the user.
Information that May Prove Helpful
- 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.
- In each record page, records are stored in alphabetical order by last
name.
- 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.
- 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:
- hash: hash takes a pointer to a character string (a last
name in this lab) and the number of leading bits in the hash
table. hash returns a hash key with the desired number of
bits.
- assign_disk_space: assign_disk_space takes a reference to
a page buffer, finds a free page on a disk, and assigns the
page to the page buffer (i.e., it sets the disk and page_num
fields of the page buffer to the appropriate values).
You should use assign_disk_space
whenever you want to get a free page on a disk (assign_disk_space
is just like malloc, but it works for external memory).
- EXTENDIBLE_HASH_TABLE constructor: The constructor initializes
the hash table to a size of 2.
It creates two index entries and two empty pages
for records, writes the two pages to disk, and makes the index
entries point to the pages. You should peruse the code in this
function to get some ideas about how your code will be written.
You should pay particular attention to how assign_disk_space
is used and to how the disk addresses of the pages are extracted
from the page buffer and assigned to the index entries.
- housekeeping: this function defines variables that
assign_disk_space needs, including a disk array. You
should not have to worry about this function.
What to Submit
- A makefile
- roster
- hsearch.cpp
- hsearch.h
- 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.