Hashing in python

Vish vahuja4 at gmail.com
Sat Feb 13 18:44:37 EST 2010


Hi,

I need to hash 3d coordinates to a grid which has been divided into
4*4*4 squares. Using python, I thought of a simple way as follows:

CELL_SIZE = 4

def key(point):

    return (
        int((floor(point[0]/CELL_SIZE))*CELL_SIZE),
        int((floor(point[1]/CELL_SIZE))*CELL_SIZE),
        int((floor(point[2]/CELL_SIZE))*CELL_SIZE)
    )


Since python allows keys to be tuples, I think that this should work.
Is there a better (more efficient) way to do it?

Thank you,
Vishal



More information about the Python-list mailing list