std.container.RedBlackTree versus C++ std::set

Dan dbdavidson at yahoo.com
Fri Feb 15 10:02:39 PST 2013


On Friday, 15 February 2013 at 17:42:30 UTC, Steven Schveighoffer 
wrote:
> On Fri, 15 Feb 2013 12:11:55 -0500, monarch_dodra 
> <monarchdodra at gmail.com> wrote:
>
>> Also keep in mind that "a < b" is implemented as two calls to 
>> "a.opCmp(b)", and "a.opCmp(b)" is itself usually implemented 
>> as two calls to "something < something else" (!)
>
> Huh?
>
> a < b is implemented as a.opCmp(b) < 0, not two calls to 
> a.opCmp(b).

Yes. But isn't opCmp still more work than just a<b? It must be 
because it returns three states instead of two. So, I think the 
general warning on opCmp is warranted especially with structs. 
For structs we could use compile time reflection to provide 
automatic efficient opCmp behavior. Section 3.1 here outlines a 
way:

https://github.com/patefacio/d-help/blob/master/doc/canonical.pdf

Any comments appreciated.

Thanks
Dan

>
> HOWEVER, when you get to the point of executing a == b, it's 
> implemented as !(a < b) && !(b < a), which could more 
> efficiently be rewritten as a.opEquals(b) or a.opCmp(b) == 0.



More information about the Digitalmars-d-learn mailing list