get number of items in DList
pgtkda via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 14 23:19:11 PDT 2014
On Friday, 11 July 2014 at 14:48:26 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
> On Fri, Jul 11, 2014 at 10:23:58AM -0300, Ary Borenszweig via
> Digitalmars-d-learn wrote:
>> On 7/11/14, 4:46 AM, bearophile wrote:
>> >pgtkda:
>> >
>> >>How can i get the number of items which are currently hold
>> >>in a
>> >>DList?
>> >
>> >Try (walkLength is from std.range):
>> >
>> >mydList[].walkLength
>> >
>> >Bye,
>> >bearophile
>>
>> So the doubly linked list doesn't know it's length? That seems
>> a bit
>> inefficient...
>
> It should be relatively simple to write a wrapper that *does*
> keep track
> of length.
>
> The main problem, though, comes from list splicing: given two
> arbitrary
> points in the list, if you splice out the section of the list in
> between, there's no easy way to know how many items lie in
> between, so
> you'll have to walk the list to recompute the length then.
> Which sorta
> defeats the purpose of having a linked list. :)
>
>
> T
I just wanted to use a DList because you can easily add new items.
The walkLength property works perfectly, thank you.
More information about the Digitalmars-d-learn
mailing list