Given your need for high-performance, you might consider a data structure that allows a binary search for your min and max values. If SortedDictionary
provided an indexer Item[int]
, you could use that but, alas, it does not.
You can consider something like
struct PriceAtTime
{
public DateTime Timestamp { get; set; }
public float Price { get; set; } // Or whatever your float represents
}
List<PriceAtTime> myData = GetTheData(); // Assumes the provided data is ordered
// by timestamp.
To find the index that contains the first data point at or after your minimum timestamp:
- Check myData[myData.Count/2]
- Depending on the value of that element's timestamp, you either found it, or the middle element is newer than the minimum so check myData.Count/4, or it's higher so check 3*myData.Count/4. Repeat recursively until you find the right element.
- Similar approach to find the index of the last element that doesn't exceed your max value.
SortedList<T>
sounds like a promising type, but in reality, it behaves much like a sorted dictionary, especially for keyed lookups.
Note that I assume the elements in the list are magically sorted. A self-sorting data structure can be fairly expensive in a real-time performance environment. If you can obtain the data already sorted from wherever it resides, you eliminate another performance concern.