dcollections 1.0 and 2.0a beta released

bearophile bearophileHUGS at lycos.com
Sat May 22 14:20:52 PDT 2010


Andrei Alexandrescu:

> Keeping the length cached in a singly-linked list is a costly mistake.
> It works against splicing (an important list primitive) and most of the
> time you don't need it so why waste time updating it.

... LinkedList(T, bool WithLength=True) {
  static if(WithLength) {
    // defines  @attribute length here etc
  }
}
Inside the methods like the add there is another static if(WithLength) that enables/disables the code that updates the length.

This allows to keep the length by default, but makes it easy to remove it when desired.

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list