I have a multithreaded simulation code doing some calculation in discrete time steps. So for each time stamp I have a set of variables which I want to store and access later on.
Now my question is:
What is a good/the best data structure given following conditions?:
- has to be thread-safe (so I guess a ordered dictionary might be best here). I have one thread writing data, other threads only read it.
- I want to find data later given a time interval which is not necessarily a multiple of the time-step size.
E.g.: I simulate values fromt=0
tot=10
in steps of1
. If I get a request for all data in the range oft=5.6
tot=8.1
, I want to get the simulated values such that the requested times are within the returned time range. In this case all data fromt=5
tot=9
. - the time-step size can vary from run to run. It is constant within a run, so the created data set has always a consistent time-step size. But I might want to restart simulation with a better time resolution.
- the amount of time stamps which are calculated might be rather large (up to a million may be)
From searching through the net I get the impression some tree-like structure implemented as a dictionary might be a good idea, but I would also need some kind of iterator/index to go through the data, since I want to fetch always data from time intervals. I got no real idea how something like that could look like ...
There are posts for finding a key in a dictionary close to a given value. But these always include some look up of all the keys in the dictionary, which might not be so cool for a million of keys (that is how I feel at least).