Re: Hashing in python

2010-02-14 Thread MRAB
Martin v. Loewis wrote: floor(x) returns an integer Why do you say that? Assuming you are talking about math.floor, it works differently for me: py> math.floor(10.0/3) 3.0 I've just double-checked. It returns a float in Python 2.x and an int in Python 3.x. (I recently switched to Python 3.1.

Re: Hashing in python

2010-02-14 Thread Martin v. Loewis
> 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 wor

Re: Hashing in python

2010-02-14 Thread Martin v. Loewis
> floor(x) returns an integer Why do you say that? Assuming you are talking about math.floor, it works differently for me: py> math.floor(10.0/3) 3.0 Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Hashing in python

2010-02-13 Thread Paul Rubin
Vish writes: > 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: Use the built-in hash function: >>> p = (1, 2, 3) >>> print hash(p) 2528502973977326415 You can of course mod that by the table siz

Re: Hashing in python

2010-02-13 Thread MRAB
Vish wrote: 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_SI

Hashing in python

2010-02-13 Thread Vish
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), i