[Python-ideas] Identity dicts and sets (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Wed Jan 2 15:01:29 CET 2013
- Previous message: [Python-ideas] Updated PEP 432: Simplifying the CPython update sequence
- Next message: [Python-ideas] Identity dicts and sets
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I propose to add new standard collection types: IdentityDict and IdentitySet. They are almost same as ordinal dict and set, but uses identity check instead of equality check (and id() or hash(id()) as a hash). They will be useful for pickling, for implementing sizeof() for compound types, and for other graph algorithms.
Of course, they can be implemented using ordinal dicts:
IdentityDict: key -> value as a dict: id(key) -> (key, value)
IdentitySet as a dict: id(value) -> valueHowever implementing them directly in the core has advantages, it consumes less memory and time, and more comfortable for use from C. IdentityDict and IdentitySet implementations will share almost all code with implementations of ordinal dict and set, only lookup function and metainformation will be different. However dict and set already use a lookup function overloading.
- Previous message: [Python-ideas] Updated PEP 432: Simplifying the CPython update sequence
- Next message: [Python-ideas] Identity dicts and sets
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]