Aaron Sherman <[EMAIL PROTECTED]> writes:

> On Tue, 2002-04-16 at 14:00, Mike Lambert wrote:
>> Speaking of which, how do we ensure the immutability of keys being put
>> into the hash? I think Perl copied the string, so that:
>> 
>> $b = "aa";
>> $a{$b} = 1;
>> chop $b;
>> print $a{"aa"};
>> 
>> still works.
>> 
>> If we start storing full thingies into the keys of a hash, we either need
>> to make deep copies of these, or copy enough to ensure the hashing
>> function has all that it needs.
>
>
> I thought about this myself, and I don't think Perl would do it that
> way. Please, Larry, et al. correct me if I'm wrong.
>
> I suspect it would involve:
>
> 1. Copying the key (which might be a reference) on insertion.
> 2. Hashing once, and caching the hash.
>
> This means a minimum of overhead, so it's a good thing. It also means
> that the structure of your hash would never need to re-compute if the
> hash of a particular object changes (which I would imagine it could
> easily do in any number of cases).

So you'd have:

   %hash{$some_obj} = $aValue;
   $some_obj.mutator;
   exists %hash{$some_obj} # returns undef. 

Somehow I *really* don't think that's going to fly.

Personally I'd like the default hash to return some immutable, unique
and probably opaque object id (something the like
'Foo=HASH(0x81e2a3c)' you get from unoverloaded objects in Perl5, but
probably not identical). This isn't going to change as an object's
contents change.

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

Reply via email to