Piers Cawley writes:
: 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.

You guys are thinking in terms of a single $obj.hash method.  I think
there will be more than one hashish (er...) method available, and each
hash will be able to choose at least whether it wants to hash by $obj._
(the default), by $obj.hash (mutable), or by $obj.id (immutable).  The
hash function is not sufficient in cases of hash collision, so you also
need to think in terms of multiple comparison methods.

Since these are just properties of the hash, the hash could even have
properties containing closures that define the hash and/or comparison
functions.  These properties can force the issue, regardless of whether
the object in question cooperates.  So you could hash objects on any
attribute or combination of attributes, for instance.

But the default is gonna look a lot like Perl 5.

Larry

Reply via email to