On 05/27/2012 04:22 AM, Andrej Mitrovic wrote:
On 5/27/12, Ali Çehreli<[email protected]> wrote:
On 05/26/2012 05:13 PM, Ali Çehreli wrote:
> once you define toHash(), you
> must also define opCmp() and opEquals() that are all consistent with
> each other.
Correction: opEquals() is only for potential optimizations. What is
needed alongside toHash() is just opCmp(), and the reason is to be able
to resolve hash collisions.
Thanks! Is this documented somewhere on dlang.org?
Yes. It is under the "Using Structs or Unions as the KeyType" section of
the Associative Arrays documentation:
http://dlang.org/hash-map.html
It actually says "The implementation may use either opEquals or opCmp or
both". So I guess opEquals() is still necessary for portability.
Ali
--
D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html