Re: hash values and equality

2011-05-21 Thread Gregory Ewing
Ethan Furman wrote: Ulrich Eckhardt wrote: If two equal objects have different hashes, they will be stored in different places in the hash map. Looking for object1 will then not turn up with object2, even though they are equal. In this case this is the behavior I want. You can't rely on

Re: hash values and equality

2011-05-21 Thread Peter Otten
Gregory Ewing wrote: Ethan Furman wrote: Ulrich Eckhardt wrote: If two equal objects have different hashes, they will be stored in different places in the hash map. Looking for object1 will then not turn up with object2, even though they are equal. In this case this is the behavior I

Re: hash values and equality

2011-05-21 Thread John Nagle
On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: For that reason, it is generally useful to use immutable types like integers, floats, strings and tuples thereof as keys. Since you can't change them, you basically have the guarantee that they hash the same. Right. It's something of a lack

Re: hash values and equality

2011-05-21 Thread Irmen de Jong
On 22-5-2011 0:55, John Nagle wrote: On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: For that reason, it is generally useful to use immutable types like integers, floats, strings and tuples thereof as keys. Since you can't change them, you basically have the guarantee that they hash the same.

Re: hash values and equality

2011-05-21 Thread Steven D'Aprano
On Sat, 21 May 2011 15:55:56 -0700, John Nagle wrote: On 5/19/2011 11:33 PM, Ulrich Eckhardt wrote: For that reason, it is generally useful to use immutable types like integers, floats, strings and tuples thereof as keys. Since you can't change them, you basically have the guarantee that

Re: hash values and equality

2011-05-20 Thread Peter Otten
Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will happen if this isn't the case? Here's a toy

Re: hash values and equality

2011-05-20 Thread Chris Rebert
On Thu, May 19, 2011 at 10:43 PM, Ethan Furman et...@stoneleaf.us wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing

Re: hash values and equality

2011-05-20 Thread Ulrich Eckhardt
Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will happen if this isn't the case? If you were

Re: hash values and equality

2011-05-20 Thread MRAB
On 20/05/2011 07:33, Ulrich Eckhardt wrote: Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will

Re: hash values and equality

2011-05-20 Thread Chris Angelico
On Sat, May 21, 2011 at 1:50 AM, MRAB pyt...@mrabarnett.plus.com wrote: [snip] Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) with the number of array elements to give an index into the array, so different hashes could

Re: hash values and equality

2011-05-20 Thread Chris Kaynor
On Fri, May 20, 2011 at 9:20 AM, Chris Angelico ros...@gmail.com wrote: On Sat, May 21, 2011 at 1:50 AM, MRAB pyt...@mrabarnett.plus.com wrote: [snip] Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) with the number of

Re: hash values and equality

2011-05-20 Thread Ethan Furman
Chris Rebert wrote: On Thu, May 19, 2011 at 10:43 PM, Ethan Furman et...@stoneleaf.us wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me

Re: hash values and equality

2011-05-20 Thread Ethan Furman
Peter Otten wrote: Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will happen if this isn't the

Re: hash values and equality

2011-05-20 Thread Ian Kelly
On Fri, May 20, 2011 at 10:36 AM, Chris Kaynor ckay...@zindagigames.com wrote: I think the question was: can this dummy code ever produce a set containing less then itemCount items (for 0 itemCount 2**32)? In CPython, no. Even when you get a hash collision, the code checks to see whether the

Re: hash values and equality

2011-05-20 Thread Ethan Furman
Ulrich Eckhardt wrote: Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will happen if this isn't the

Re: hash values and equality

2011-05-20 Thread Ethan Furman
Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ Two things I didn't make clear originally: I'm using Python3. My objects (of type Wierd) obey the

Re: hash values and equality

2011-05-20 Thread Chris Rebert
On Fri, May 20, 2011 at 10:56 AM, Ethan Furman et...@stoneleaf.us wrote: Chris Rebert wrote: On Thu, May 19, 2011 at 10:43 PM, Ethan Furman et...@stoneleaf.us wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this

Re: hash values and equality

2011-05-20 Thread Christian Heimes
Am 20.05.2011 17:50, schrieb MRAB: Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) with the number of array elements to give an index into the array, so different hashes could give the same index, and objects with different

Re: hash values and equality

2011-05-20 Thread MRAB
On 20/05/2011 20:01, Christian Heimes wrote: Am 20.05.2011 17:50, schrieb MRAB: Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) with the number of array elements to give an index into the array, so different hashes could

Re: hash values and equality

2011-05-20 Thread Peter Otten
Ethan Furman wrote: Peter Otten wrote: Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will

Re: hash values and equality

2011-05-20 Thread Ethan Furman
Peter Otten wrote: Ethan Furman wrote: Peter Otten wrote: Ethan Furman wrote: Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ -- class Wierd(): ... def

Re: hash values and equality

2011-05-20 Thread Steven D'Aprano
On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: On 20/05/2011 20:01, Christian Heimes wrote: Am 20.05.2011 17:50, schrieb MRAB: Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!) ... I don't think 'moduloed' is an existing

Re: hash values and equality

2011-05-20 Thread MRAB
On 21/05/2011 01:47, Steven D'Aprano wrote: On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: On 20/05/2011 20:01, Christian Heimes wrote: Am 20.05.2011 17:50, schrieb MRAB: Is this strictly true? I thought that the hash value, an integer, is moduloed (Is that how you spell it? Looks weird!)

Re: hash values and equality

2011-05-20 Thread Steven D'Aprano
On Sat, 21 May 2011 02:02:48 +0100, MRAB wrote: On 21/05/2011 01:47, Steven D'Aprano wrote: On Fri, 20 May 2011 21:17:29 +0100, MRAB wrote: On 20/05/2011 20:01, Christian Heimes wrote: Am 20.05.2011 17:50, schrieb MRAB: Is this strictly true? I thought that the hash value, an integer, is

hash values and equality

2011-05-19 Thread Ethan Furman
Several folk have said that objects that compare equal must hash equal, and the docs also state this http://docs.python.org/dev/reference/datamodel.html#object.__hash__ I'm hoping somebody can tell me what horrible thing will happen if this isn't the case? Here's a toy example of a class I'm