AA with complex keytype?
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Fri Feb 9 06:19:45 PST 2007
Manfred Nowak wrote:
> For complex numbers comparisons other than == and != are not defined.
Indeed.
> AA's require classes to have comparisons defined.
Also correct.
> Why are AA's of complex numbers allowed?
For one thing, complex numbers aren't classes :P.
Seriously: AA's use the TypeInfo.compare() method to compare. For
complex types, this is implemented as lexicographical ordering (compare
the real parts, and return the result unless it's equal; in that case,
return the result of comparing the imaginary parts).
The reason "<" and friends aren't defined for complex types is that
there's no definition that makes any mathematical sense (at least, not
more than other definitions).
Fortunately, AA's don't require the ordering to make any mathematical
sense at all, they just need some way to decide in what order to put
them in a binary three if a hash collision should occur. As long as the
order is consistent[1] (a < b && b < c => a < c, that sort of thing)
they're happy.
[1]: I'm sure there's a mathematical term for this that I can't
currently remember.
More information about the Digitalmars-d
mailing list