PEP 372 -- Adding an ordered directory to collections

"Martin v. Löwis" martin at v.loewis.de
Tue Jun 17 18:34:32 EDT 2008


> I think I have lost the thread here, sorry. So I explain again what I
> mean. I think for this data structure it's important to keep all the
> normal dict operations at the same speed. If you use a C
> implementation vaguely similar to my pure python recipe you can
> perform the del in O(1) too, because pairs are joined in (double)
> linked list. But such data structure is O(n) to find the n-th item
> inserted into the sequence.

Right. So byindex(n) would be O(n) then, right? If so, what's the
purpose of having that method in the first place?

The PEP doesn't give a rationale, but just proposes that the method
be there. My guess is that it includes it for performance reasons.
However, I think the PEP (author) is misguided in assuming that
making byindex() a method of odict, you get better performance than
directly doing .items()[n] - which, as you say, you won't.

Regards,
Martin



More information about the Python-list mailing list