For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
Design a key-value store that supports versioning through timestamps. The problem is divided into three parts with increasing complexity.
Implement a basic key-value store with set and get operations.
KV kv = new KV();
kv.set("foo", "bar");
kv.get("foo"); // Returns "bar"
Extend the basic store to support versioning. The set operation returns a timestamp, and get can optionally take a timestamp to retrieve historical values.
KV kv = new KV();
long timestamp = kv.set("foo", "bar");
Thread.sleep(1000); // Wait 1 second
kv.set("foo", "bar2");
// Get value at specific timestamp
kv.get("foo", timestamp); // Returns "bar"
// Get latest value
kv.get("foo"); // Returns "bar2"
Extend Part 2 to support getting values at any point in time, not just exact timestamps. When given a timestamp, return the most recent value that was set before that timestamp.
KV kv = new KV();
long timestamp = kv.set("foo", "bar");
Thread.sleep(1000);
kv.set("foo", "bar2");
// Get latest value
kv.get("foo"); // Returns "bar2"
// Get value at timestamp + 750ms
kv.get("foo", timestamp + 750); // Returns "bar"
Design a key-value store that supports versioning through timestamps. The problem is divided into three parts with increasing complexity.
Implement a basic key-value store with set and get operations.
KV kv = new KV();
kv.set("foo", "bar");
kv.get("foo"); // Returns "bar"
Extend the basic store to support versioning. The set operation returns a timestamp, and get can optionally take a timestamp to retrieve historical values.
KV kv = new KV();
long timestamp = kv.set("foo", "bar");
Thread.sleep(1000); // Wait 1 second
kv.set("foo", "bar2");
// Get value at specific timestamp
kv.get("foo", timestamp); // Returns "bar"
// Get latest value
kv.get("foo"); // Returns "bar2"
Extend Part 2 to support getting values at any point in time, not just exact timestamps. When given a timestamp, return the most recent value that was set before that timestamp.
KV kv = new KV();
long timestamp = kv.set("foo", "bar");
Thread.sleep(1000);
kv.set("foo", "bar2");
// Get latest value
kv.get("foo"); // Returns "bar2"
// Get value at timestamp + 750ms
kv.get("foo", timestamp + 750); // Returns "bar"
Output