| 
            
             Be the first user to complete this post  
            
             | 
         Add to List | 
474. Implement/Design the version control map system
Problem: Implement the version control map system which takes the snapshot of the versions of data. Implement the following functions:
- put(key, value) - puts the value again the key in the latest version of the map
 - get(key) - get the value of the key for the latest version of the data
 - snapshot() - take a snapshot and increment the version
 - getValVersion(version id, key) - return value of the key of the particular version
 - getCurrentVersion() - return the latest/current version
 
Example:
Operations
put("memory", "16GB")
put("os_version", "10")
put("graphics", "intel_10_153")
snapshot()
put("os_version", "11")
put("graphics", "intel_11_153")
get("graphics"))
getCurrentVersion())
getValVersion(0, "graphics"))
get("os_version"))
Output:
graphics in current version: intel_11_153
Current Control Map version is : 1
graphics in version 0 : intel_10_153
os_version in current version: 11
Approach: Use Map of maps
- The first map will have the version of the control map system as key and the second map as value.
 - The second map will store the key-value pairs of attributes of a particular version of the control map.
 - Integer currentVersion will represent the latest version at any point of time.
 - put(key, value) - Insert a key-value pair in the second map against the current_version in the first map.
 - get(key) - Get the value from the second map for the given key against the current_version in the first map
 - snapshot() - do old_version = current_version. Increment the current_version by 1 and then insert all the values from old_version to current_version.
 - getValVersion(version_id, key) - Get the value from the second map for the given key against the version_id in the first map. If version_id does not exist, print the error message.
 - getCurrentVersion() - return the current_version.
 
Output:
Initializing Version Control Map System graphics in current version: intel_11_153 Current Control Map version is : 1 graphics in version 0 : intel_10_153 os_version in current version: 11
Reference: https://www.careercup.com/question?id=5708770181644288