poll for properties

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jul 28 17:03:36 PDT 2009


Andrei Alexandrescu wrote:
> Bill Baxter wrote:
>> On Tue, Jul 28, 2009 at 4:16 PM, bearophile<bearophileHUGS at lycos.com> 
>> wrote:
>>
>>> Another solution for D code (that I have used in my Set data 
>>> structure. But it contains a negation):
>>> if (!b.length) {...}
>>
>> The rationale for .empty is that .length could be an O(n) operation
>> for some containers, but .empty should always be O(1).  So, the
>> negation of  .length is not a general replacement for .empty.
> 
> Exactly.
> 
> Andrei

Damn, I was wrong here. If you can't define .length in O(1), just don't 
define it. But that means it may not be defined :o). Iron logic, heh. If 
you just want the length and don't mind the complexity, call walkLength.

Andrei



More information about the Digitalmars-d mailing list