Ken MacLeod ken@bitsko.slc.ut.us
Wed, 9 Sep 1998 11:38:04 -0500 (CDT)

Fredrik Lundh writes:
> Andrew M. Kuchling writes:
> > That seems like a reasonable strategy, but how do you determine
> >what the parent reference should be, in general?  It's obviously
> >trivial to construct a proxy for some special cases, such as the
> >children of a node, but how would you find the parent of a node
> >without actually storing a reference to it?  Storing a
> >non-reference, such as an integer ID?  Walking the tree?  Something
> >else?

> The iterator uses a a parent list which is updated when you move
> around in the tree.  If you go down, it adds the current node to the
> parent list.  If you go up, it removes a node.

The way I implemented it, I created a new proxy object for next, prev,
first_child, etc.  The proxy object carried a `parent' member that
pointed back to the parent _proxy_, so instead of a list it was a
chain back up to the parent.

In this case, the proxy-iterator isn't an iterator in the sense that
it has a ``current node'' and you point the iterator to new nodes by
calling next, prev, first_child, etc.  Instead, the iterator functions
actually return a new proxy.

This technique also allows you to pass proxy-iterators around as
easily as nodes themselves.