optimized immutable containers
monarch_dodra
monarchdodra at gmail.com
Wed Jul 3 01:04:43 PDT 2013
On Wednesday, 3 July 2013 at 07:22:00 UTC, w0rp wrote:
> I suppose you could implement an efficiently copied immutable
> singly linked list like this very easily. I think that's a
> basic functional programming idea, new list with head + list.
> Making the nodes garbage collected would save on memory usage.
The irony here (as stated by Bearophile) is that this is
currently how our SList and DList are actually implemented: Not
value nor ref semantics: Just shared owner ship of nodes...
EG:
--------
import std.stdio, std.container;
void main()
{
alias SLI = SList!int;
auto a = SLI(1);
auto b = a;
auto c = a;
b.insertFront(0);
c.insertFront(2);
writeln("a[]: ", a[]);
writeln("b[]: ", b[]);
writeln("c[]: ", c[]);
}
--------
a[]: [1]
b[]: [0, 1]
c[]: [2, 1]
--------
-_-
More information about the Digitalmars-d
mailing list