On Sun, Sep 6, 2009 at 12:06 PM, Ville M. Vainio <[email protected]> wrote:
> > On Sun, Sep 6, 2009 at 7:53 PM, Edward K. Ream <[email protected]> > wrote: > > > 2. Generators returning (unified)nodes simply use the corresponding > > position generators. Thus, all such generators must be members of the > > commands or position class, *not* the vnode class. > > > > def allNodes(c): > > for p in allPositions(c): > > yield p.v > > raise StopIteration > > I think it would be a better idea to bypass positions for this > generator, because we can implement *much* more efficient generators > by using nodes alone. Also, the node generator could return the whole > parent stack (because it maintains it anyway). > This can't be correct, for several reasons. Most importantly, iterators are naturally related to positions, not nodes. It would thus be bad design to have iterators be part of a node class. Except for some unusual special cases in the read logic (when positions don't yet exist), Leo (properly) treats position as the essential data to have, and nodes as derived from positions. Changing this would greatly (and wrongly) change Leo's core. I'm not going to do it. Instead, the contemplated revision merely replaces clumsy code by elegant code. Second, (v)nodes are never enough, by themselves, to generate most kinds of "next" positions. Two more data are needed for the next position to be well defined: the specific parent of the node and the node's child index. The p.moveToX methods used by the present (and future) iterators pass such data to the low-level vnode methods. Finally, the data structures needed by your suggested node iterators are available to positions via p.v. Thus, if need be, we could implement the same optimizations you contemplate for vnode-based iterators in the position class. I have no appetite for further optimizations. The code is good, and previous optimizations have been complex. However, I won't rule them out entirely, if it turns out that optimizations are much easier to do in the one-node world. Edward --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "leo-editor" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en -~----------~----~----~----~------~----~------~--~---
