On Wed, Jun 22, 2016 at 2:50 AM, Raymond Hettinger
<raymond.hettin...@gmail.com> wrote:
>
>> On Jun 21, 2016, at 10:18 AM, Guido van Rossum <gu...@python.org> wrote:
>>
>> Judging from Inada's message there seems to be some confusion about how well 
>> the compact dict preserves order (personally I think if it doesn't guarantee 
>> order after deletions it's pretty useless).
>
> Inada should follow PyPy's implementation of the compact dict which does 
> preserve order after deletions (see below).

I follow it, for most cases.

When my compact dict doesn't preserve order is using PEP 412 Key sharing dict.


>>> class A:
...   ...
...
>>> a = A()
>>> b = A()   # a and b shares same keys, and have each values
>>> a.a = 1
>>> a.b = 2   # The order in shared key is (a, b)
>>> b.b = 3
>>> b.a = 4
>>> a.__dict__.items()
dict_items([('a', 1), ('b', 2)])
>>> b.__dict__.items()
dict_items([('a', 4), ('b', 3)])


It's possible to split keys when the insertion order is not strictly same.
But it decrease efficiency of key sharing dict.

If key sharing dict is effective only such a very strict cases,
I feel __slots__ can be used for it.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to