-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simplify tree diff algorithm #12
Conversation
iavl/iavl.py
Outdated
get_node: GetNode, | ||
v: int, | ||
predecessor: int, | ||
successor: int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any usage of successor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, cleaned up.
iavl/iavl.py
Outdated
predecessor: int, | ||
root: bytes, | ||
successor_root: bytes, | ||
) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should return node right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should return nothing, fixed.
iavl/utils.py
Outdated
@@ -330,26 +335,26 @@ def visit_iavl_nodes( | |||
stack: List[bytes] = [hash] | |||
while stack: | |||
hash = stack.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we rename like hash_or_node
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if isinstance(hash, tuple): | ||
# already expanded, (hash, node) | ||
if isinstance(hash, PersistedNode): | ||
# the postorder case, it's already expanded as PersistedNode | ||
yield hash | ||
continue | ||
|
||
node = get_node(hash) | ||
|
||
if not preorder: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we need postorder now, but need loop all anyway right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
postorder is only used in import/export, which we haven't implemented in python version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what loop all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless prune_check is different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, without prune_check it'll traverse all.
Co-authored-by: mmsqe <[email protected]> Signed-off-by: yihuang <[email protected]>
The algorithm is adapted from cosmos/iavl#646, credits: @cool-developer
The new one visit the same amount of nodes as the previous one, but is simpler.
It could be further optimized after new node key format, because we can traverse nodes with whatever order, so we can just traverse them ordered by node key with the version as prefix.