CMSC 246 Systems Programming

Spring 2021


Assignment #4: Hashtables

Due: Mar 24: before 11:59:59 PM

In this assignment you will build two versions of a very basic hashtable.

Your hashtable should have the following properties:

For example: here is an input file:
    put dfsdfs 7
    put dklsjfds 20
    put d 234
    put ff 345
    put ee 456
    put ff 567
    put gg 678
    put hh 789
    put ii 890
    put jj 990
    put kk 901
    put mm 012
    get ee 1
    get ff 1
    get mm 1
    get dfsdfs 1
    rem ff 1
    rem kk 1
    get mm
    put ff 1024
    put gg 2048
    put zzz 4096
and here is a trace output from that input. Note that I made a very small hashtable and got it quite full. This was intentional as only be being pretty full can you really test probing. (You do not need to have the same output, and indeed I encourage you to innovate as there are many ways in the output could be clearer.)
    [gtowell@powerpuff HW4a]$ cat inp.txt | ht 13
    PUT 8  8
    PUT 8  9
    PUT 6  6
    PUT 8  10
    PUT 7  7
    PUT 8  10
    PUT 9  11
    PUT 10  12
    PUT 11  0
    PUT 12  1
    PUT 0  2
    PUT 2  3
    GET ee  456
    GET ff  567
    GET mm  12
    GET dfsdfs  7
    REM ff  1
    REM kk  1
    GET mm  12
    PUT 8  10
    PUT 9  11
    PUT 2  2
    The Hashtable
    =============
       0                    ii   890
       1                    jj   990
       2                   zzz  4096
       3                    mm    12
       4                           0
       5                           0
       6                     d   234
       7                    ee   456
       8                dfsdfs     7
       9              dklsjfds    20
      10                    ff  1024
      11                    gg  2048
      12                    hh   789
    

Reading the input file

I suggest that you use fgets to read stdin line by line then strtok to separate items on the line (use a space as the splitting character). However, that is not required.

Part 1: 70%

In the first part you will implement the hashtable using standard array notation. You may use pointers in dealing with strings. Otherwise you should use array notation. Get this completely working before going on to part 2

Part 2: 30%

In the second part you should use only pointers and pointer math. Therefore in the second part, the only use of [] should be in the lines that actually create arrays.

What to submit:

Collect together in a single directory all of the following: When you have everything ready in this directory, then go to the directory containing the one with the information you want to submit. For instance, suppose that the files specified above are in /home/YOU/cs246/a4. Then you should go to /home/YOU/cs246.
Use the submit program as follows:
  /home/gtowell/bin/submit -c 246 -p 4 -d a4
This will package up everything in the directory a4 and submit it under your login name along with a timestamp of your submission date.

Back to CMSC246 Home page