Ready for review: new std.uni

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Jan 13 02:39:21 PST 2013


13-Jan-2013 13:58, Chad J пишет:
> On 01/13/2013 02:28 AM, Jonathan M Davis wrote:
>>
>> I really should ask Andrei why he made length require O(log n) instead
>> O(1)...
>>
>> - Jonathan M Davis
>
> Are there cases where it can't be O(1)?
>

> My current intuition is that length can always be cached.

Caching of length is suitable for adapters on top of base/core containers.

>  If a
> container has a long length calculation, then it can be shortened by
> wrapping it in a proxy container that does nothing but expose the same
> operations as jackets around the original container.  These jackets
> forward all data in and out with no changes, except for one: they count
> the number of elements entering and leaving the underlying container and
> store this count in a length variable.
>

Yeah, exactly.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list