Find if keys are in two dimensional associative array

Ali Çehreli acehreli at yahoo.com
Sun Jan 17 13:47:42 PST 2010


Michal Minich wrote:
 > On Sun, 17 Jan 2010 11:28:49 -0500, bearophile wrote:
 >
 >> In D the built in AAs require an equality test and/or cmp, plus opHash.

AAs require all three for classes: opEquals, opCmp, and toHash. Further, 
opEquals and opCmp must be consistent: when opEquals returns true, opCmp 
must return 0, and when opCmp returns non-zero, opEquals must return false.

toHash is optional for structs.

 > Why should AAs require opCmp. What if object is not logically sortable,
 > (like Guid, DbConnection, ...). Equality & Hash should be enough...
 > Is the opCmp here to optimize lookup? Because opCmp may be quite slow,
 > which may affect appending performance...

I don't know the answer, but the spec says so at

   http://digitalmars.com/d/2.0/arrays.html

<quote>
The implementation may use either opEquals or opCmp or both. Care should 
be taken so that the results of opEquals and opCmp are consistent with 
each other when the class objects are the same or not.
</quote>

Ali


More information about the Digitalmars-d-learn mailing list