title: Data structure for storing and sorting different objects/types? Storing various different sensor data, sorted by time
body: <p>I am trying to come up with a solution for holding different types of sensor data sorted and in order by time.
  So for example I will have:</p>
  <ul>
  <li>GNSS/GPS data at times 100, 101, 102, etc.</li>
  <li>IMU data at times 100, 100.01, 100.02, .... 101, 101.01, etc.</li>
  <li>Lidar data at times 100, 100.1, 100.2, ... 101.1, 101.2, etc</li>
  </ul>
  <p>I need to process the data in order of time. They are different types/objects.
  Right now I am doing something crude like:</p>
  <pre><code># The actual data structures stored would look something like below 
  # (with some fields not explicity written out for clarity, the point though is each 
  # data structure is different).
  # 
  # struct GnssData {
  #    double time; double latitude; double longitude; };
  # struct ImuData {
  #    double time; double acc_x; double acc_y; }; 
  # struct LidarData {
  #    double time; double ranges[100]; double angles[100]; };
  
  # We can assume each individual list/array/vector is sorted by time. 
  # The actual implementation right now is std::vector&lt;LidarData&gt; all_lidar_data; std::vector&lt;GnssData&gt; all_gnss_data; std::vector&lt;ImuData&gt; all_imu_data;
  all_lidar_data = [100, 100.1, 100.2, 100.3, 100.4, 100.5]
  all_gnss_data = [100, 101, 102, 103]
  all_imu_data = [100, 100.01, 100.02, 100.03]
  
  if all_lidar_data[0].time &lt; all_gnss_data[0].time and all_lidar_data[0].time &lt; all_imu_data[0].time:
    # process lidar data
    # pop all_lidar_data[0]
  elif all_gnss_data[0].time &lt; all_lidar_data[0].time and all_gnss_data[0].time &lt; all_imu_data[0.time:
    # process gnss data
    # pop all_gnss_data[0]
  </code></pre>
  <p>This kind of works but it gets really messy when there is no gnss data for example, so the list/array is empty. Thus also need to check if there is gnss data first before doing the time comparison.</p>
  <p>Ideally what I would like to do is have some array that contains all the sensor data in order of time, so its as simple as</p>
  <pre><code>while len(all_sensor_data) &gt; 0:
    # process all_sensor_data[0]
    # remove all_sensor_data[0]
  </code></pre>
  <p>Where all_sensor_data, using the example above, would be: GNSS(100), IMU(100), Lidar(100), IMU(100.01), ... IMU(100.09), Lidar(100.1), IMU(100.1), ..., GNSS(101), IMU(101), Lidar(101),</p>
  <p>Is there any suggestions on a design pattern, or data structure that may solve this issue? Im technically programming in c++ but wrote the examples in python for clarity.
  Edit: This is a real time application so data is continuously added when its available.</p>