title: Is there a proximity map algorithm or data structure?
body: <p>A problem I keep running into when writing code that draws images of scientific data is the following:</p>
  
  <p>Given some floating point data, fit those data into slots (1-dimensional case) or a grid (2-dimensional case) such that each datum is in the slot or grid entry whose value is closest to the datum's value.</p>
  
  <p>It is not the case that the slot/grid values are evenly spaced.</p>
  
  <p>For example, put the following data into the following slots:</p>
  
  <p>data: 0.1, 0.6, 4.23, 5.1, 7.0</p>
  
  <p>slots: 0.0, 0.4, 0.6, 1.2, 5.0, 10.0</p>
  
  <p>In practice, there are far more data than there are slots.  So it would be beneficial to have a data structure that kept the slots in cache together.</p>
  
  <p>What would be nice is something like a tree or a hash table, where you ask the tree for the value that corresponds to a key, but with sloppy comparisons that yield the closest match.</p>
  
  <p>Does such a beast exist?</p>
  
  <p>(Right now, I just have loops that do lots of comparisons.  It seems like I could at least do better by using a binary search through the slots, though...)</p>