Skip to content
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

Merged
merged 6 commits into from
Dec 13, 2022
Merged

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Dec 12, 2022

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.

@yihuang yihuang changed the title simplify diff algorithm simplify tree diff algorithm Dec 12, 2022
@yihuang yihuang requested a review from mmsqe December 12, 2022 07:50
iavl/iavl.py Outdated
get_node: GetNode,
v: int,
predecessor: int,
successor: int,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any usage of successor?

Copy link
Collaborator Author

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/cli.py Outdated Show resolved Hide resolved
iavl/iavl.py Outdated
predecessor: int,
root: bytes,
successor_root: bytes,
) -> int:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return node right?

Copy link
Collaborator Author

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()
Copy link

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?

Copy link
Collaborator Author

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:
Copy link

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what loop all?

Copy link

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

Copy link
Collaborator Author

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.

yihuang and others added 2 commits December 13, 2022 09:57
Co-authored-by: mmsqe <[email protected]>
Signed-off-by: yihuang <[email protected]>
@yihuang yihuang merged commit 49a8a8b into crypto-com:main Dec 13, 2022
@yihuang yihuang deleted the refactor-diff branch December 13, 2022 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants