[Python-Dev] PEP for new dictionary implementation (original) (raw)
Mark Shannon mark at hotpy.org
Fri Feb 17 18:52:23 CET 2012
- Previous message: [Python-Dev] PEP for new dictionary implementation
- Next message: [Python-Dev] PEP for new dictionary implementation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 17 February 2012 at 17:42 Jim Jewett <jimjjewett at gmail.com> wrote:
On Fri, Feb 17, 2012 at 1:50 AM, "Martin v. Löwis" <martin at v.loewis.de> wrote: >>> Good idea. However, how do you track per-dict how large the >>> table is?
[Or, rather, what is the highest index needed to store any values that are actually set for this instance.] > To determine whether it needs to grow the array, it needs to find out > how large the array is, no? So: how do you do that? Ah, now I understand; you do need a single ssizet either on the dict or at the head of the values array to indicate how many slots it has actually allocated. It may also be worthwhile to add a second ssizet to indicate how many are currently in use, for faster results in case of len. But the dict is guaranteed to have at least one free slot, so that extra index will never make the allocation larger than the current code.
The dict already has a field indicating how many items are in use, the ma_used field.
Cheers, Mark.
- Previous message: [Python-Dev] PEP for new dictionary implementation
- Next message: [Python-Dev] PEP for new dictionary implementation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]