Mark Dickinson wrote: > On Fri, Mar 19, 2010 at 9:37 AM, Mark Dickinson <dicki...@gmail.com> wrote: > For ints, this hash function is almost identical to what Python > already has, except that the current int hash does a reduction modulo > 2**32-1 or 2**64-1 rather than 2**31-1. For all small ints, hash(n) > == n, as currently. Either way, the hash can be computed > digit-by-digit in exactly the same manner. For floats, it's also easy > to compute: express the float as m * 2**e for some integers m and e, > compute hash(m), and rotate e bits in the appropriate direction. And > it's straightforward to implement for the Decimal and Fraction types, > too.
It seems to me that given the existing conflation of numeric equivalence and containment testing, going the whole hog and fixing the set membership problem for all of our rational types would be the right thing to do. Would it be worth providing the underlying implementation of the hash algorithm as a math.hash_rational function and then use it for Decimal and Fraction? That would have the virtue of making it easy for others to define numeric types that "played well" with numeric equivalence. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com