On Sun, Aug 13, 2023 at 12:10 PM Edward K. Ream wrote:
> c.*alt*_all_positions must use a stack just like Position.stack.
True, but c.alt_all_positions is simpler than I dared hope:
def alt_all_positions(self) -> Generator:
"""An alternative implementation of c.all_positions."""
c = self
PositionStack = list[tuple[VNode, int]]
def visit(childIndex: int, v: VNode, stack: PositionStack) -> Generator:
yield leoNodes.Position(v, childIndex, stack[:])
stack.append((v, childIndex))
for child_childIndex, child_v, in enumerate(v.children):
yield from visit(child_childIndex, child_v, stack)
stack.pop()
stack: PositionStack = []
for i, v in enumerate(c.hiddenRootNode.children):
yield from visit(i, v, stack)
No helper methods required! This method passes
TestNodes.test_c_alt_all_positions:
def test_c_alt_all_positions(self):
c = self.c
self.clean_tree()
cc = self.create_test_paste_outline()
assert cc.h == 'cc', repr(cc)
positions1 = list(c.all_positions())
positions2 = list(c.alt_all_positions())
assert positions1 == positions2
An amazing development. The birthday presents keep coming.
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/CAMF8tS0hu1U6Hs8Fqe64PkEKkay9EdDC7qQWHZws0GreeSv4PQ%40mail.gmail.com.