[Python-ideas] An identity dict  Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl Wed Jun 2 00:05:31 CEST 2010  2010/6/1
Benjamin Peterson <benjamin at python.org>:  > My contention is
that an identity dictionary or at least a dictionary with >
custom hash and keys is a useful primitive that should be in the
standard > library. However, I also see its advantage in
avoiding bad performance of id() > based identity dicts in non-
CPython implementations. > It is useful to let the
implementation optimize it any time there is moving GC > as in
Jython and IronPython where id also is expensive. (Basically a
mapping has > to be maintained for all objects on which id is
called.)  Here is how I designed this for my language:  You can
request the ObjectId of the given object. If an ObjectId
corresponding to the given object is still alive, you always get
it back again, but it can be GC'ed and later created afresh.
ObjectIds are hashable and comparable (with an arbitrary
ordering). Hash values and the ordering are preserved