python - Fastest data structure for numerically indexed data structure? -
i using regular python 2.79 , want use standard libaries. want create 2 dimensional array, each cell referenced 2 dimensions point small dictionary of miscellaneous data. want fastest way access cell containing dictionary. data have 2 integer indexes can reference each cell. know x , y (let's call them..)
1) x , y elements have permissible values between -58600 , +58600.
2) not every cell contain information, need , cell data numerical x,y index.
3) contents of data cell size or configuration , change on time, upgrade code or include new parameters, etc.
my first thought nested dictionary such that
dictionary_structure[x][y]["data"]
would data .. or test exists by
if "data" in dictionary_structure[x][y]:
what sort of data structure should use fastest lookup?
i think performance improve if have 1 top-level dictionary, rather 1 each dimension. here few possibilities:
use tuples:
if (x, y) in dictionary_structure: print(dictionary_structure[(x, y)]["data"])
multiply 1 coordinate number of possible values it, , add other (your keys integers; multiplication ensures no unique combination of x
, y
become same key - wrap key computation in function; can use division , modulo extract x , y key):
key = 117201 * x + y if key in dictionary_structure: print(dictionary_structure[key]["data"])
i don't know of these faster in situation; need measure yourself.
Comments
Post a Comment