#C10732. Simple In-Memory Database
Simple In-Memory Database
Simple In-Memory Database
This problem requires you to implement a simple in-memory key-value database supporting four operations:
- PUT k v: Store the value v with key k. If the key already exists, update its value.
- GET k: Retrieve the value associated with key k, or output
NULL
if the key does not exist. - DELETE k: Remove the key k and its associated value if it exists.
- COUNT v: Return the number of keys that have the value v.
The commands are provided via standard input and the output for each GET and COUNT command should be printed to standard output. Use the following input format:
n command1 command2 ... commandn
For example, a sample execution might be:
6 PUT key1 value1 GET key1 PUT key1 value2 GET key1 COUNT value1 COUNT value2
with the output:
value1 value2 0 1
Note: When dealing with formulas or mathematical expressions in your solution, use LaTeX format, such as $E=mc^2$
.
inputFormat
The first line contains an integer (n) representing the number of commands. The next (n) lines each contain a command in one of the following formats:
• PUT k v • GET k • DELETE k • COUNT v
Here, k and v are strings without spaces.
outputFormat
For each command of type GET and COUNT, output the result on a new line to stdout.## sample
6
PUT key1 value1
GET key1
PUT key1 value2
GET key1
COUNT value1
COUNT value2
value1
value2
0
1
</p>