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 > > array elements to give an index into the array, so different hashes > > could give the same index, and objects with different hashes could be > > stored in the same 'bucket'. > > There can always be hash collisions between different objects, but the > assumption is that two identical objects will _always_ "collide". I think the question was: can this dummy code ever produce a set containing less then itemCount items (for 0 < itemCount < 2**32)? itemCount = 100 import itertools counter = itertools.count().next class Test(object): def __init__(self): self.hash = counter() def __hash__(self): return self.hash def __eq__(self, other): return True set((Test() for i in xrange(itemCount))) > Chris Angelico > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list