[Python-Dev] gc ideas -- sparse memory
Stephen J. Turnbull
stephen at xemacs.org
Sat Dec 4 13:33:06 CET 2010
Steven D'Aprano writes:
> Martin v. Löwis wrote:
> >> It seems counter-productive to me to bother with an identity function
> >> which doesn't meet that constraint. If id(x) == id(y) implies nothing
> >> about x and y (they may, or may not, be the same object) then what's the
> >> point?
> >
> > See James' explanation: it would be possible to use this as the
> > foundation of an identity hash table.
>
> I'm afraid James' explanation didn't shed any light on the question to
> me. It seems to me that Java's IdentityHashValue[sic -- I think the
> correct function name is actually IdentityHashCode] is equivalent to
> Python's hash(), not to Python's id(), and claiming it is related to
> identity is misleading and confusing.
Not quite equivalent. Python's hash() obeys a certain additional
constraint (that numeric values that compare equal have the same
hash), and IdentityHashValue presumably won't work at all on numbers
in Java (since they aren't objects).
Bikeshedding aside, I have to agree with you: there's no point in
calling such a function id() or IdentityAnything(). Everything you
need to know (including both the fact that it could be an efficient
way to search for a unique object, and the possible non-uniqueness of
the object assigned that code) is contained in the word "hash".
More information about the Python-Dev
mailing list