Ready for review: new std.uni

Chad J chadjoan at __spam.is.bad__gmail.com
Sun Jan 13 01:58:16 PST 2013


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



More information about the Digitalmars-d mailing list