From: Nicolas C. <war...@fr...> - 2004-09-11 10:02:33
|
> On the subject of Dllist.enum... I noticed that the count () > function always computes the length of the remaining nodes > by traversing the list. It would be more efficient to do > this, I think: > > 1) The first time count () is called, compute the length > and store it "in the enum". > > 2) Subsequent calls to count () just return the computed > length. > > 2) Every time next () is called, decrese the number of > remaining elements by 1 (if the number hasn't been set, > you don't need to do anything). > > This would only incur minimal overhead for next () and for > any code the uses count () it basically reduces count () > to O(1) averaged over all the elements. This is actually the implementation of List.enum. Jesse you can have a look at it to implement it. Nicolas |