AA with complex keytype?

Manfred Nowak svv1999 at hotmail.com
Fri Feb 9 12:51:29 PST 2007


Stewart Gordon wrote

>> Currently AA's misbehave if opCmp(Object) is not overwritten for
>> a class, but no error is thrown.
> Currently?  Not under DMD 1.005 as I try it.  Please supply a code
> example that demonstrates this behaviour. 

Following code shows under 1.005 that no compile time error is given.

class C{
  hash_t toHash() { 
    return 0;
  }
}
void main(){
  bool[C] map;
  map[ new C]= true;
  map[ new C]= false;
}

A runtime error shows up only, when a comparison is actually needed.
This might be far too late. In this example the runtime error is forced 
by implementing a worthless toHash. 


> So if x != y, then both x < y and y < x?  That wouldn't make sense
> at all. 

Enough sense for an AA: all colliding elements are put into a linear 
list and searched in sequence on retrieval. Without a good toHash this 
would natrally lead to a bad runtime behaviour.

-manfred  



More information about the Digitalmars-d mailing list