Program in c that implements snapshot


Implementation details:

Write a program in C that implements Snapshot DB as shown in the examples below. You can assume that our test cases will contain only valid input commands and not cause any integer overflows. Keys are case sensitive and do not contain spaces. Commands are case insensitive. Entry values are indexed from 1. Snapshots are indexed from 1 and are unique for the lifetime of the program. Keys, entries and snapshots are to be outputted in the order from most recently added to least recently added.

Your program must be contained in snapshot.c and snapshot.h and produce no errors when built and run on the lab machines and Ed. Reading from standard input and writing to standard output.

Your program output must match the exact output format shown in the examples and on Ed. You are encouraged to submit your assignment while you are working on it, so you can obtain some feedback.

The contents of an example header file snapshot.h are shown below

#ifndef SNAPSHOT_H
#define SNAPSHOT_H

#define MAX_KEY 16
#define MAX_LINE 1024

typedef struct entry entry;
typedef struct snapshot snapshot;

struct entry {
char key[MAX_KEY];
int* values;
size_t length;
entry* next;
entry* prev;
};

struct snapshot {
int id;
entry* entries;
snapshot* next;
snapshot* prev;
};
#endif

In order to obtain full marks, your program must free all of the dynamic memory it allocates. This will be automatically checked using address sanitizer. If your program produces the correct output for a given test case and does not free all memory it allocates, then it will not pass the given test case.

Commands:

Your program should implement the following commands, look at the examples to see how they work.

• If a does not exist in the current state, output: no such key

• If a does not exist in the database, output: no such snapshot

• If an does not exist in an entry, output: index out of range

BYE clear database and exit
HELP display this help message

LIST KEYS displays all keys in current state
LIST ENTRIES displays all entries in current state
LIST SNAPSHOTS displays all snapshots in the database

GET displays entry values
DEL deletes entry from current state
PURGE deletes entry from current state and snapshots

SET sets entry values
PUSH pushes values to the front
APPEND appends values to the back

PICK displays value at index
PLUCK displays and removes value at index
POP displays and removes the front value

DROP deletes snapshot
ROLLBACK restores to snapshot and deletes newer snapshots
CHECKOUT replaces current state with a copy of snapshot
SNAPSHOT saves the current state as a snapshot

MIN displays minimum value
MAX displays maximum value
SUM displays sum of values
LEN displays number of values

REV reverses order of values
UNIQ removes repeated adjacent values
SORT sorts values in ascending order

DIFF displays set difference of values in keys
INTER displays set intersection of values in keys
UNION displays set union of values in keys

> BYE
bye

Writing your own testcases:

We have provided you with some test cases but these do not not test all the functionality described in the assignment. It is important that you thoroughly test your code by writing your own test cases. You should place all of your test cases in the tests/ directory. Ensure that each test case has the .in input file along with a corresponding .out output file. We recommend that the names of your test cases are descriptive so that you know what each is testing, e.g. get-set.in and sort-uniq.in

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Program in c that implements snapshot
Reference No:- TGS01238455

Expected delivery within 24 Hours