On Sun, Aug 13, 2023, Edward K. Ream wrote:

>> Is it possible to write [*c.all_vnode_positions*]?

> You bet: [snip]

> This generator passes the following consistency test:


vnodes1 = [c.hiddenRootNode] + [z.v for z in c.all_positions()]

vnodes2 = list(c.all_vnode_positions())

assert vnodes1 == vnodes2


The elegance of this VNode-based stand-in for c.all_positions raises some
follow-on questions.


*Does c.all_positions use v.parents?*


Apparently not, which means that c.all_vnode_positions isn't strictly
necessary. Leo could define it like this:


def all_vnode_positions(self):

    c = self

    yield c.hiddenRootNode

    for p in c.all_positions():

        yield p.v


But this definition would be much worse than a VNode-based definition.


*c.alt_all_positions*


Could Leo define a generator, say *c.alt_all_positions*, using
c.all_vnode_positions as a template? Yes it could.


In my original post, I said, "[c.all_vnode_positions] will maintain an
explicit stack just like Position.stack." In fact, the generator uses only
a stack of VNodes. But c.*alt*_all_positions must indeed use a stack just
like Position.stack.


c.all_positions calls p.moveToThreadNext to advance through the outline. In
turn, p.moveToThreadNext calls p.moveToParent, p.moveToFirstChild and
p.moveToNext.


c.*alt*_all_positions will use none of these helpers. Instead, the new
generator will operate directly on its explicit stack, yielding new
positions with (copies of) the explicit stack. There will be no need for a
"copy" kwarg.


*Summary*


*c.alt_all_positions* is feasible. Similarly, Leo could define other "alt"
generators.


Alt generators should be faster (and use less memory) than the
corresponding legacy generators.


Nevertheless, Positions themselves and all Position methods must remain,
whatever their internal form.


Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS1-NtBYKghZHe1rPZaRcFa6x5GKavzsLyioF%2BgnhA_19A%40mail.gmail.com.

Reply via email to