I have a large array (>1 million) of 3-dimensional points, a 3-tuple (x, y, z) which takes float values. The points are bounded between (0,0,0) and (Nx, Ny, Nz). I am interested in finding the index of a point coming from some calculation, say R, which is present somewhere in this array. What is the fastest way of doing this? Is there any O(1) algorithm to search for R through the array? The good thing is that the distance between any two points is always greater than 0.005.
I have been thinking of creating a hash-table for storing the index of all the points in the array, but I need a good hash-function that can convert (x, y, z) to a unique hash-key. Is there a simple hash-function that can do that? Is there any C-based library that will help?
A simple hash-function which I thought could generate a unique hash-key is:
h(x,y,z) = 1000*x + 1000000*y + 1000000000*z
This is followed by creating another integer array P of size = max(h), and storing the index of (x,y,z) at P[h(x,y,z)] (rounding-off needs to be taken care). The worry is the size of array P - is this approach good enough for this problem?
Alternative to hash would be using k-d tree. In terms of run-time, which performs better, hash-key or tree-based approach?
(I am using C for this work).