Associative arrays, opCmp, opEquals and toHash in 2.066.0-b4

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 21 11:52:23 PDT 2014


On Mon, Jul 21, 2014 at 06:28:48PM +0000, w0rp via Digitalmars-d wrote:
> A rule I learned from writing Java is that if you implement equality,
> you must also implement hashing, and if you implelement hashing you
> must implement equality. I believe this is actually a general truth of
> programming in any language, and now D has the right kind of
> semantics.

This should generally be obvious, since the AA has to hash the object,
then distinguish between objects with the same hash by comparing them
with some kind of comparison operator. Obviously, if the hash function
is inconsistent with this comparison operator, then you're going to get
inconsistent behaviour out of the AA.

Now, one *could* argue that in some cases, you could implement custom
equality but use the default hash function, because you know that your
custom equality is consistent with it, but I'd say this is a risky
assumption because if it turns out that it's actually *not* consistent,
then you end up with a very hard-to-trace bug. So in general, requiring
that either you use default equality and hash, or redefine both, seems
to be the most logical approach.


> On an off topic note, I noticed your signature, H.S. Teoh.
> 
> >"640K ought to be enough" -- Bill G., 1984.
> 
> That quote is well known for being fabricated. The year varies wildly.
> There's no evidence of Bill ever saying it which isn't someone saying,
> "Trust me, I heard him say it once."

Funny, your reply prompted me to search for the attribution, and I came
across this:

	http://imranontech.com/2007/02/20/did-bill-gates-say-the-640k-line/

Of course, most of my quotes are meant to be humorous in some way, so
they shouldn't be taken 100% seriously. So I just changed it to:

	"640K ought to be enough" -- Bill G. (allegedly), 1984.
	"The Internet is not a primary goal for PC usage" -- Bill G.,
	1995.
	"Linux has no impact on Microsoft's strategy" -- Bill G., 1999.

;-)


T

-- 
Computers are like a jungle: they have monitor lizards, rams, mice, c-moss, binary trees... and bugs.


More information about the Digitalmars-d mailing list