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

Improvements to the code of Merkle Patricia Trie doc #12720

Closed
croath opened this issue Apr 12, 2024 · 1 comment
Closed

Improvements to the code of Merkle Patricia Trie doc #12720

croath opened this issue Apr 12, 2024 · 1 comment
Assignees
Labels
content 🖋️ This involves copy additions or edits

Comments

@croath
Copy link
Contributor

croath commented Apr 12, 2024

The original code sample from

def update(node,path,value):
if path == '':
curnode = db.get(node) if node else [ NULL ] * 17
newnode = curnode.copy()
newnode[-1] = value
else:
curnode = db.get(node) if node else [ NULL ] * 17
newnode = curnode.copy()
newindex = update(curnode[path[0]],path[1:],value)
newnode[path[0]] = newindex
db.put(hash(newnode),newnode)
return hash(newnode)
is:

    def update(node,path,value):
        if path == '':
            curnode = db.get(node) if node else [ NULL ] * 17
            newnode = curnode.copy()
            newnode[-1] = value
        else:
            curnode = db.get(node) if node else [ NULL ] * 17
            newnode = curnode.copy()
            newindex = update(curnode[path[0]],path[1:],value)
            newnode[path[0]] = newindex
        db.put(hash(newnode),newnode)
        return hash(newnode)

Shall we streamline the code a little bit with reducing the repeating part, like:

    def update(node,path,value):
        curnode = db.get(node) if node else [ NULL ] * 17
        newnode = curnode.copy()
        if path == '':
            newnode[-1] = value
        else:
            newindex = update(curnode[path[0]],path[1:],value)
            newnode[path[0]] = newindex
        db.put(hash(newnode),newnode)
        return hash(newnode)
@github-actions github-actions bot added the needs triage 📥 This issue needs triaged before being worked on label Apr 12, 2024
@minimalsm minimalsm added content 🖋️ This involves copy additions or edits and removed needs triage 📥 This issue needs triaged before being worked on labels Apr 12, 2024
@minimalsm
Copy link
Contributor

Closed by #12721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content 🖋️ This involves copy additions or edits
Projects
None yet
Development

No branches or pull requests

2 participants