title: two way ranged lookup table, C#
body: <p>I need to take a design decision on some data structure for extremely quick access. Here the scenario :
  I have to sync two variables of different growth rate. I have tabulated data of in the following format:</p>
  
  <p>Range( Ai1, Ai2)  ~  Range ( Bi1, Bi2)    That is to say that the range Ai1 - Ai2 matches Bi1 - Bi2 for some i</p>
  
  <p>Now given any Ax in the entire span of A I should be able to determine the appropriate range in (Bj1, Bj2) and vice-versa. Data type wise : A is int;  while B is float.</p>
  
  <p>I don't know what would be the most appropriate data type for this translation ? My primary requirement is speed. Also any help in how this data struct can be implemented in C# would be helpful.  </p>
  
  <p>The problem is assured to fit in memory. Span of A can be approx the range 0 - 300,000, and the  size of range Ai1-Ai2 can be some where from 10 to 300 ; while the span of span of the float is 0 to 10,000.000  ( we use only 3 decimal places) and the size of range Bi1 - Bi2 can be something like 0.100 - 10.000 </p>
  
  <p>Another known fact is that A is assured to be continuous while B may not be. But both increase sort of simultaneously, but at varying rates.Also neither Ranges overlap. Both are  monotonically increasing.</p>
  
  <p>So something like this can be expected: </p>
  
  <p>(Ai1,  Ai2)  ~ ( Bi1, Bi2)</p>
  
  <p>(1,78) ~ (13.454, 19.546)</p>
  
  <p>(79,114) ~ (19.712,22.335)</p>
  
  <p>(115, 198) ~ ( 22.678, 24.101)</p>
  
  <p>query:  A = 99 , Expected Response: B range = (19.712,22.335)</p>
  
  <p>query: B = 16.117 , Expected Response: A range= (1,78)</p>
  
  <p>In case B is not in range forward roundoff is expected.</p>
  
  <p>Thnx-Egon</p>