storing/retrieving data for graph with long continuous stretches

Posted by james on Stack Overflow See other posts from Stack Overflow or by james
Published on 2010-03-21T04:35:33Z Indexed on 2010/03/21 4:41 UTC
Read the original article Hit count: 347

Filed under:
|

i have a large 2-dimensional data set which i would like to graph. the graph is displayed in a browser and the data is retrieved via ajax.

long stretches of this graph will be continuous - e.g., for x=0 through x=1000, y=9, then for x=1001 through x=1100, y=80, etc.

the approach i'm considering is to send (from the server) and store (in the browser) only the points where the data changes.

so for the example above, i would say data[0] = 9, then data[1001] = 80. then given x=999 for example, retrieving data[999] would actually look up data[0].

the problem that arises is finding a dictionary-like data structure which behaves like this. the approach i'm considering is to store the data in a traditional dictionary object, then also maintain a sorted array of key for that object. when given x=999, it would look at the mid-point of this array, determine whether the nearest lower key is left or right of that midpoint, then repeat with the correct subsection, etc..

does anyone have thoughts on this problem/approach?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about datastructures