title: Time ordered data structure
body: <p>I have a large amount of data that is retrieved from a database.  They are ordered by timestamp (which each item has) and I wish to quickly scroll smoothly through this data as well as being able to retrieve the next/previous record given a specific time.</p>
  
  <p>Is there any data structure that will help me do this?  At the moment I do a kind of binary search through the data to retrieve the next items.</p>
  
  <p>Inserts, deletions and edits are rare (but occasionally necessary) so seek time is the most critical.</p>
  
  <p>Any ideas?</p>
  
  <p>A simple example:</p>
  
  <pre><code>public class TimedDataItem
  {
      DateTime Timestamp { get; set; }
  }
  
  // Large populated timestamped data set    
  IList&lt;TimedDataItem&gt; timedDataItemsList = new Last&lt;TimedDataItem&gt;();
  
  // Get a 'random' time
  DateTime myTime = DateTime.Now;
  
  // Find items around that 'random' time
  TimedDataItem next = timedDataItemsList.FirstOrDefault(t=&gt;t.Timestamp &gt; myTime);
  TimedDataItem previous = timedDataItemsList.LastOrDefault(t=&gt;t.Timestamp &lt; myTime);
  
  // Also foreach over the collection in time order if required
  foreach (TimedDataItem item in timedDataItemsList)
      DoStuff(item);
  
  // Inserts, deletions, edits are extremely rare
  </code></pre>
  
  <p>Thanks.</p>