Object.toString, toHash, opCmp, opEquals

Timon Gehr timon.gehr at gmx.ch
Fri Apr 26 13:46:21 UTC 2024


On 4/26/24 15:27, Timon Gehr wrote:
> Ideally, `opEquals` implements an equivalence relation. It is fine if it changes the representatives in the process, as long as it properly encapsulates the internal state such that whenever two values compare equal, the observable semantics of the two representatives is the same.
> ...
> If you want something that is actually useful, you will have to look 
> into splay trees or something like that. Or e.g., maybe you have a ring 
> buffer or something that compacts itself on iteration. As I said, 
> amortized data structures. It may be incorrect to have a const opEquals. 
> It can introduce a performance regression.

Jonathan's examples with concurrency are also a very good practical 
illustration of this.


More information about the Digitalmars-d mailing list