container stuff

Andrei Alexandrescu SeeWebsiteForEmail at
Wed May 26 08:54:11 PDT 2010

On 05/26/2010 07:44 AM, Pelle wrote:
> On 05/26/2010 11:44 AM, bearophile wrote:
>> Andrei A.:
>>> I hope to work with ranges only.<
>> Programming life is complex, you can't fit all of it in one schema ("A
>> foolish consistency is the hobgoblin of little minds").
> Couldn't you just define opApply where you need it and it will be used
> where foreach is used by default, anyway?
>>> Will look into it, sounds like an implementation matter.<
>> Yes, right. But to implement this idea the foreach() has to change a
>> bit, to set the flag in nonrelease mode. If implemented this idea
>> lessens a bit the need for the stable ("soft") methods.
>>> Probably some trees could save some state if they exploit O(log n)
>>> length.<
>> In general a length can be O(n) if for example you want to compute it
>> on a linked list that doesn't keep the number of items inserted. Are
>> you going to just not give a length attribute for such linked lists
>> (so users have to use something like walkLength)?
> Isn't that a good thing? If I know length is fast, I can use it without
> worries, but if it might be O(n) you need to avoid it.

Yes, that's exactly the idea.

BTW, I'd misunderstood the question. Bearophile asked "Why O(log n) and 
not O(n)?" and I heard: "Why O(log n) and not O(1)?" So I'd gotten 
confused a bit and answered the wrong question.


More information about the Digitalmars-d mailing list