Skip to content

Instantly share code, notes, and snippets.

@eob
Created December 22, 2016 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eob/5398fb5e5f125465a90cf03c803e09e8 to your computer and use it in GitHub Desktop.
Save eob/5398fb5e5f125465a90cf03c803e09e8 to your computer and use it in GitHub Desktop.

Consider the general concept of a map, dictionary, or hash data structure.

E.g.

set( key: "a", value: 1 )
set( key: "b", value: 10 )
get( key: "a" ) returns 1
get( key: "b" ) returns 10

For this exercise, implement a map with history.

In this map, when you set a value, you also specify a time at which the key becomes that value, and stays that value until changed again. So, when you get the value of a key, you ask for the value of that key at a particular time.

E.g.

set( time: 0, key: "a", value: 1 )
set( time: 2, key: "a", value: 2 )
get( time: 0, key: "a" ) returns 1
get( time: 1, key: "a" ) returns 1
get( time: 2, key: "a" ) returns 2
get( time: 3, key: "a" ) returns 2
get( time: 4, key: "a" ) returns 2
...

You could use a data structure like this for time-series data storage, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment