lab04 : Hash Tables

num ready? description assigned due
lab04 true Hash Tables Mon 02/04 08:00AM Sun 02/10 11:59PM

Goals

By the end of this lab, you will be able to:

Step by Step

Step 0: Getting Started

This lab may be done solo, or in pairs.

Before you begin working on the lab, please decide if you will work solo or with a partner.

As stated in previous labs, there are a few requirements you must follow if you decide to work with a partner. I will re-iterate them here:

Once you and your partner are in agreement, choose an initial driver and navigator, and have the driver log into their account.

Step 1: Get the lab04 starter code into your repository directory

In this step, we are going to copy the lab04 starter files from the instructors directory into your ~/cs32/lab04 directory.

The files are in the instructors directory at

~richert/public_html/cs32/misc/lab04/*

and also accessible via the URL

http://cs.ucsb.edu/~richert/cs32/misc/lab04/

You want to copy these files into your ~/cs32/lab04 directory.

Step 2: Write the table.h header file

Write table.h to define class Table as it is used in the demonstration program named tabledemo.cpp. Your Table must hold Entry objects as defined in entry.h (and implemented in entry.cpp). For the demonstration program to compile successfully, your table.h must define at least the following public functions:

Your class may define other functions too, either public or private ones. In particular, you will probably want to add a hashing function to transform the key values - in our version, function hashkey is a private function. And of course, your class must define the private data a Table object stores.

HINT: You will want to use chained hashing for this lab. That means that each row in your Table will be of type std::vector<Entry>. It is often convenient to typedef that type to some shorter name, so your method signatures don’t get clunky.

Step 3: Write the Table class to implement the header from Step 2

Write table.cpp to implement your class Table. You may use tools from any of the standard libraries except <map>, <set>, <unordered_map> and <unordered_set>.

Hint: write stub code for each method, and get your class to compile. Then filling in the methods is a SMOP (Simple Matter of Programming).

In planning your implementations, keep in mind the following requirements:

Clarification about Big-O restrictions:
It is important that you store and manipulate Entry objects (i.e., instances of class Entry), and not separately handle the integer keys and string data. That is because we assess the efficiency of your functions by using the Entry::access_count() function before and after various operations. The time tests used by Gradescope will fail if they detect impossibly small counts of Entry accesses. Do notice that sorting Entry objects is no more complicated than sorting numbers, thanks to the operator conversion function that allows an Entry object to be treated like an int when appropriate. So, for example, if e1 and e2 are both entry objects, then (e1 < e2) will evaluate to true if e1.key() is less than e2.key(). All of the other relational operators work too! The power of overloading.

Step 4: Testing

Compile and test your program at CSIL. Create your own testing program(s) to do so. After you think that all parts are working properly, you should verify that your implementation compiles and executes correctly with the demonstration program too. Use the following command to compile it:

g++ -std=c++11 -o tabledemo tabledemo.cpp table.cpp entry.cpp

The demonstration also requires a copy of the file fips.txt (Federal Information Processing Standard codes for all U.S. counties) to reside in your current working directory. (This file is provided along with the other ones.)

Step 5: Submitting via Gradescope

You will turn in both table.h and table.cpp.

The lab assignment “Lab04” should appear in your Gradescope dashboard in CMPSC 32. If you haven’t submitted anything for this assignment yet, Gradescope will prompt you to upload your files.

For this lab, you will need to upload your modified files (i.e. table.h and table.cpp). You either can navigate to your file, “drag-and-drop” them into the “Submit Programming Assignment” window, or even use your private GitHub repo in our class organization to submit your work.

If you already submitted something on Gradescope, it will take you to their “Autograder Results” page. There is a “Resubmit” button on the bottom right that will allow you to update the files for your submission.

For this lab, if everything is correct, you’ll see a successful submission passing all of the autograder tests.

Remember to add your partner to Groups Members for this submission on Gradescope if applicable. At this point, if you worked in a pair, it is a good idea for both partners to log into Gradescope and check if you can see the uploaded files for Lab04.