What kind of data structure should I use if I have a bunch of the following data:
MyData
{
float ValueA;
float ValueB;
object OtherInfo;
}
And I need to quickly find all MyData
instances that meet this kind of criteria:
0.5 <= ValueA <= 0.7 AND 0.2 <= ValueB <= 0.9
It's simple to find these items, but I need it to be done as fast as possible. Is there a data structure ideal for this? I don't mind using up extra memory.
My current idea is to have a sorted list, sorted by ValueA. Then I would do a binary search to find the first item that has a ValueA >= 0.5, and iterate until I get an item with ValueA > 0.7. For each iteration, I check if the ValueB is between 0.2 and 0.9. I put all the matching items in my output dataset.
Is there a better/faster way of doing it?
I'm using C#, by the way.