Re: Length of an SLIst ?

2012-04-02 Thread bearophile
Steven Schveighoffer: It all depends on how you model the data. If the data is contained/owned by a single instance, then you can store the length inside that instance. If it's not owned (i.e. sublists are also valid SLists) then you cannot do that. Let me add something to your answer. Wit

Re: Length of an SLIst ?

2012-04-02 Thread Andrej Mitrovic
On 4/2/12, Steven Schveighoffer wrote: > (i.e. sublists are also valid SLists) I haven't thought of that, good point. :)

Re: Length of an SLIst ?

2012-04-02 Thread Justin Whear
On Mon, 02 Apr 2012 23:10:40 +0200, Andrej Mitrovic wrote: > On 4/2/12, Justin Whear wrote: >> Classic singly-linked lists must be iterated to determine length > > I'm no algorithms buff, but I don't understand the benefit of not > storing the length in the SList. What does it cost to maintain a

Re: Length of an SLIst ?

2012-04-02 Thread Steven Schveighoffer
On Mon, 02 Apr 2012 17:10:40 -0400, Andrej Mitrovic wrote: On 4/2/12, Justin Whear wrote: Classic singly-linked lists must be iterated to determine length I'm no algorithms buff, but I don't understand the benefit of not storing the length in the SList. What does it cost to maintain an ex

Re: Length of an SLIst ?

2012-04-02 Thread Ali Çehreli
On 04/02/2012 02:10 PM, Andrej Mitrovic wrote: > On 4/2/12, Justin Whear wrote: >> Classic singly-linked lists must be iterated to determine length > > I'm no algorithms buff, but I don't understand the benefit of not > storing the length in the SList. What does it cost to maintain an > extra var

Re: Length of an SLIst ?

2012-04-02 Thread Andrej Mitrovic
On 4/2/12, Justin Whear wrote: > Classic singly-linked lists must be iterated to determine length I'm no algorithms buff, but I don't understand the benefit of not storing the length in the SList. What does it cost to maintain an extra variable? It's a single increment/decrement on each add/remov

Re: Length of an SLIst ?

2012-04-02 Thread Andrej Mitrovic
On 4/2/12, Justin Whear wrote: > Classic singly-linked lists must be iterated to determine length, so use > std.range.walkLength on it. Specifically call it on its range. You can get a range by slicing the slist, e.g.: import std.range; import std.container; void main() { auto s = SList!int

Re: Length of an SLIst ?

2012-04-02 Thread Justin Whear
On Mon, 02 Apr 2012 22:42:23 +0200, Chris Pons wrote: > I'm trying to find the length of a Slist. I've tried using the built in > .length function but it generates this error: "Error: no property > 'length' for type 'SList!(Node)'". Are there any other built in ways to > find the length? Classic

Length of an SLIst ?

2012-04-02 Thread Chris Pons
I'm trying to find the length of a Slist. I've tried using the built in .length function but it generates this error: "Error: no property 'length' for type 'SList!(Node)'". Are there any other built in ways to find the length?