develooper Front page | perl.perl6.language | Postings from March 2005

Re: Valid hash keys?

Thread Previous | Thread Next
From:
Alex Burr
Date:
March 1, 2005 15:54
Subject:
Re: Valid hash keys?
Message ID:
20050301235144.GA6842@glasloc
On Sun, Feb 27, 2005 at 03:36:42PM -0700, Luke Palmer wrote:
> But the biggest problem is that if the user overloads 'equal' on two
> objects, the hash should consider them equal.  We could require that to
> overload 'equal', you also have to overload .hash so that you've given
> some thought to the thing.  The worry I have is that people will do:
> 
>     method hash() { 0 }

This is why I think a  'canonicalize' method is better than a
.hash' method: if canonicalize is defined correctly, then .equal
is just {$a.canon() is_bitwise_identical_to $b.canon()}, so
people don't have to supply both. Quite often when you would ordinarily
define a .equal method, it is of that form anyhow. And then .hash
can be straightforwardly defined as {$_.canon().binaryhash()}, where
binaryhash() just means hash all the memory of this object. 

 Stringify would be an instance of a canonicalization function; and
perhaps the default.

 
Alex

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About