Steve White <stevan.wh...@gmail.com> writes: > ... > A little documentation would have saved me personally days of work. > It would be helpful to know: > * under what conditions can one expect a "perfect hash", that is, > one where __eq__() will never be called?
Never expect it: keys with different hash values may end up in the same "dict" slot - and then "__eq__" may be used for disambiguation even with a perfect hash function. > * is it sufficient to return the value of the key object's id() > function to produce a perfect hash? Usually. Exceptions are (maybe among others): persistent objects (i.e. objects which live longer than a process), situations during shutdown (during shutdown, an object may be released even if there are still references to it; it might be possible that during this phase the same address is reused even if at some other place there is still an implicit use of the old object). > * when might it be useful to consider keying by identity? Suboptimal question. Follow Python's standard "dict" key management paradigm (which is equality based). If this does not fit, then look for the approach that fits your **special** case. > * what are the limitations of programming this way? With "this way", you mean "identity based dicts"? Then, you have already got several limitations in this thread. -- https://mail.python.org/mailman/listinfo/python-list