Generating a tree structure
Ricky C via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 21 07:09:22 PDT 2014
I'm trying to make a tree data structure in part of my first
non-trivial D-based program. Turns out that DMD likes to re-use
PODs - sounds good, but that trapped me, and I'm not sure how to
clear myself out of the problem nicely.
My simplified, but not oversimplified, example is
http://dpaste.dzfl.pl/67b022ca029e
You'll note in the output of the program several duplicated
values for "self" and the parent value goes to places other than
the parent. This is all wrong, and shows my ignorance, but is as
far as I've been able to work it.
In my operational code I bypassed the problem by storing every
leaf and branch in an array and changing the self, parent, and
children properties to be indices into said array. But this
feels hackish: I'd rather have the tree itself hold everything it
needs.
Note: I'm not stuck with a struct. I could class the thing, but I
figured that a struct holds what I need simply...
Thoughts, solutions?
More information about the Digitalmars-d-learn
mailing list