0

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 from t=0 to t=10 in steps of 1. If I get a request for all data in the range of t=5.6 to t=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 from t=5 to t=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).

Ch L
  • 76
  • 7
  • Look up Sorted Map applications for things like Flight Databases. – Marichyasana Oct 07 '20 at 14:04
  • 1
    If you can build the data structure in a sorted way (or sort it later) _and_ you know the step-size, you can even use a list. The indices of the desired interval can be calculated then. – Wups Oct 07 '20 at 14:15
  • @Wups - Thanks! That actually is a nice idea and I went for it. Works well so far. – Ch L Oct 14 '20 at 06:16

0 Answers0