> I'm finding the vnode code harder to read, but if it works better then it 
> is better :-). However, is it better because you are the one who wrote it 
> instead of me :-), or because it is easier to avoid mistakes using vnodes? 
>

Well I didn't tried too hard to make it more readable. It can be improved. 
But changing tree using vnodes has several benefits. First of all, vnodes 
are stable (immune to tree changes) - positions are not. The second they 
work much faster because every change in the tree performed through 
positions are followed by a redraw and a lot of code that doesn't need to 
be executed until the complete tree change is done. You don't usually want 
to see intermediate versions of tree. You want to see the finished tree. 
When making changes using vnodes, nothing is redrawn until you explicitly 
call `c.redraw()`.

Iterating through every node is at least 2-3 times faster using vnodes than 
using position iterators.

 

> I'll take a close look at it and add the insert functionality I also had 
> in my code. Maybe that way I will if/how out how vnodes help avoid the 
> mistakes.
>
> About this comment:
>         # if you need to keep track of headlines and boides too
>         # yield v, tuple(v.children), tuple(v.parents), v.h, v.b
>
> The function make_snapshot creates a snapshot of data needed to recreate 
subtree structure. In the variant where no changes to headlines nor bodies 
are made, this function takes enough data to undo the changes. However if 
you need to keep record of headlines and bodies too, then you should add 
them too to snapshot. Of course  in that case you must change the function 
from_snapshot too. 
def from_snapshot(data):
    for v, children, parents, h, b in data:
        v.children[:] = children
        v.parents[:] = parents
        v.h = h
        v.b = b

def make_snapshot(v0):
    def it(v):
        yield v, tuple(v.children), tuple(v.parents), v.h, v.b.b
        for ch in v.children:
            yield from it(ch)
    return tuple(it(v0))

This two functions can store and recreate the exact copy of the given 
vnode. If you want to make snapshot of the whole outline, pass the 
c.hiddenRootNode as the argument to the make_snapshot function. However, if 
you are certain that the only changes made are under one vnode (for example 
@ftlist node), then it is more efficient to store only subtree of @ftlist.

HTH Vitalije

-- 
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/ff4fed4b-4833-4b58-a369-8d7dab2fb2a6%40googlegroups.com.

Reply via email to