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

monarch_dodra monarchdodra at gmail.com
Fri Feb 15 10:08:59 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).

Right... sorry.

But still, calling opCmp is usually a bit more expensive that a 
simpler function dedicated to giving you a < b.

99% of the time, I agree that it doesn't matter mutch, and the 
gain in semantic power trumps performance, but for a dedicated 
algorithm, eg sort, there is a definite performance difference...

> 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.

And that.


More information about the Digitalmars-d-learn mailing list