[Python-Dev] Dictionary sparseness
Brett Cannon
drifty@alum.berkeley.edu
Sun, 4 May 2003 16:27:16 -0700 (PDT)
[Raymond Hettinger]
> I have two competing proposals to expose dictresize():
>
> 1) d.resize(minsize=0)
>
> The first approach allows a user to trigger a resize(). This is handy
> after deletions have taken place and dictionary contents have become
> stable. It allows the dictionary to be rebuilt without dummy entries.
<snip - explanation of method>
The issue I see with this is people going overboard with calls to this.
I can easily imagine a new Python programmer calling this after every
insertion or deletion into the dictionary. I can even see experienced
programmer getting trapped into this by coming up with a size and then
coding themselves into a corner by trying to maintain the size. I also
see people coding a size that is optimal and then changing their code but
forgetting to change the value passed to the method, thus negating the
perk of having this option set
> 2) d.setsparsity(factor=1)
>
> The second approach does not allow dictionaries to be pre-sized,
> but the effects do not get wiped out by normal dictionary activity.
>
<snip>
This is more reasonable. Since it is a factor it will makes sense to
beginners who view it as a sliding scale and also allows more experienced
programmers to set it to where they know they want the performance. And
setting the value will more than likely be good no matter how the code is
changed since the use of the dictionary will most likely stay consistent.
Do either hinder dictionary performance just by introducing the possible
functionality?
I am -1 on 'resize' and +0, teetering on +1, for setsparsity. I will kick
over to +1 if someone else out there with more experience with newbies can
say strongly that they don't see them messing up with this option.
-Brett
P.S.: Thanks, Raymond, for doing all of this work and documenting it so
well.