[Python-Dev] I think my set module is ready for prime time; comments?
Thu, 25 Jan 2001 02:50:13 +0200 (IST)
On Wed, 24 Jan 2001 10:41:07 -0500, Guido van Rossum <email@example.com> wrote:
> > Cool idea, but even cooler (would catch more idioms, that is) is
> > "the first time someone stores something not 'is' something in the
> > dict, allocate the values array". This would catch small numbers,
> > None and identifier-looking strings, for the measly cost of one
> > pointer/dict object.
> Sorry, but I don't understand what you mean by the ^^^ marked phrase.
> Can you please elaborate?
I should really stop writing incomprehensible bits like that. Heck,
I can't even understand it on second reading.
I meant that the dictionary would keep a slot for "the one and only
value". First time someone puts a value in the dict, it puts it
in the "one and only value" slot, and doesn't initalize the value
array. The second time someone puts a value, it checks for pointer
equality with that "one and only value". If it is the same, it
it still doesn't initalize the value array. The only time when
the dictionary initalizes the value array is when two pointer-different
values are put in.
This would let me code
a[key] = None
For my sets (but consistent in the same set!)
a[key] = 1
When the timbot codes (again, consistent in the same set)
a[key] = 'present'
If you're really weird.
(identifier-like strings get interned)
That's not *semantics*, that's *optimization* for a commonly
used (I think) idiom with dictionaries -- you can't predict
the value, but it will probably remain the same.
Moshe Zadka <firstname.lastname@example.org>
This is a signature anti-virus.
Please stop the spread of signature viruses!
Fingerprint: 4BD1 7705 EEC0 260A 7F21 4817 C7FC A636 46D0 1BD6