master

Challenge: Write an in-memory, key-value value store that can “time travel.”

Basic operations

You should be able to get and set values for arbitrary keys. In Ruby, this might look something like:

kv = KV.new
kv.set('foo', 'bar')
kv.get('foo')
=>  "bar"

Advanced operations

If a timestamp is provided for a given key, fetch the value for that key at that particular time. If no timestamp is supplied, fetch the most recently set value for that key. In Ruby, this might look like:

kv = KV.new
kv.set('foo', 'bar')
now = Time.now.to_i
sleep(1)
kv.set('foo', 'bar2')

# Fetch the key 'foo' with the 'now' timestamp
kv.get('foo', now)
=> "bar"

# Fetch the key 'foo' without a timestamp
kv.get('foo')
=> "bar2" # returns the last set value

Bonus points

Support ‘fuzzy’ matching on a timestamp.

kv = KV.new
now = Time.now.to_i
kv.set('foo', 'bar')
sleep(3)
kv.set('foo', 'bar2')

# Fetch the key 'foo' with the 'now' timestamp, plus 2 seconds
kv.get('foo', now + 2)
=> "bar" # returns the closest set value to that timestamp, but always in the past