The Question
CodingThread-Safe Versioned Key-Value Store
Design and implement a thread-safe, timestamp-based key-value store. The data structure should support two main operations:
1.
set(key, value, timestamp): Stores the value associated with key at the given timestamp.
2. get(key, timestamp): Returns the value associated with the given key such that the stored timestamp is the largest value less than or equal to the requested timestamp. If no such value exists, return null or an empty string.
Constraints:
- The implementation must be thread-safe and handle concurrent reads and writes.
- The get operation should be optimized for performance, ideally $O(\log N)$ where $N$ is the number of versions for a specific key.
- Multiple values can be stored for the same key at different timestamps.Java
ConcurrentHashMap
ConcurrentSkipListMap
Binary Search