This assignment enters with 3% into the total grade!
Assignment 4
- Write a data safe library offering the following
functionality:
- Calling data_safe(ds_register, 0, 0) will return a
unique random key (a positive integer). Use
rand() to
generate random numbers (and man rand to find out how).
- Calling data_safe(ds_store, key, value) will store the
value (a positive integer) in the data safe (under the key). It
should return the value if everything worked, -1 otherwise
(e.g. if there is no space left)
- Calling data_safe(ds_retrieve, key, n) will
retrieve the nth value stored under the key, or -1 if
less then n values have been stored under the key
- Calling data_safe(ds_delete, key, 0) will delete all
entries stored under key (you may then reuse key for future
register calls, as long as you still generate a random key)
- Make sure that at least 100 keys can be in use in parallel,
and that at least 10000 data items can be stored in total
- Make sure that the data is not accessible in any other way
(using legal C)
- Implement the libray in its own source file, with a header file
data_safe.h that contains all necessary
declarations
- Write a main program ds_test.c that uses the library,
storing 10 values under 3 different keys, retrieving them and
delete them. Use a reasonably varied sequence of storage, retrieval,
and registration
- Hints:
- Use static local variables to store the necessary data in the
data_safe() function
- Use preprocessor #define statements to define the
symbolic constants ds_register,
ds_store,...
- Be careful to avoid handing a key already in use out on
registration. Carefully design your data structures first, the
operations will be simple to implement
- Don't be too concerned about efficiency!
Stephan
Schulz,schulz@cs.miami.edu, Thu Aug 22 13:35:31 EDT 2002