Homework is important practice for you, but it’s not graded so you don’t have to submit it.
The fifth homework assignment deals, for the first time, with modules in C. Unlike in previous assignments, you’re not writing a complete C program for this one. Instead, you are implementing an interface for a simple data structure and you’ll write test cases for that implementation as described below. The resulting library module is general enough to be used in a variety of applications.
A key-value store is a simplistic database.
It can store associations between keys (think social security number or
last name or URL) and values (think address or phone number or popularity
For this assignment, the data is not even stored persistently on disk, it
just exists in memory for as long as a client program runs.
(If you’re familiar with Java, think of a key-value store as a
you’re familiar with Python, think of it as a
On Piazza you’ll find a file
kvs.h that describes the
interface to our key-value store.
Make sure that you read the interface carefully and understand what each
operation is supposed to do before you start hacking!
Your job is to write
kvs.c to implement all the operations from
You’ll have to decide how to store the data which will in turn determine
the code you’ll have to write to access/update it.
Please do not introduce additional modules, put all the code for the
key-value store into
Just writing a module without having any indication of whether it works
or not is a really bad idea.
So concurrently with your code for
kvs.c you should develop a simple
unit test driver called
assert as we did in
Remember that this kind of test driver stops running on a failed assertion,
so essentially all your assertions must pass.
test_kvs.c make sure that you exercise all of the code in
In addition to
kvs.h you need
test_kvs.c as well as a
Makefile with the usual
Since there is no designated “main program” the
probably also run the tests by default.
You won’t need a shell script for unit testing, you’ll run the
However, you probably still want to use
valgrind as part of testing.
kvs.his supposed to do, ask!
structcan be used to collect a bunch of different data types under one name, that might be useful.
kvs.ccode into sensible functions. Make sure that only functions and variables that should be accessible are actually accessible from the outside. (Remember the