Skip to content

Commit a09b7d0

Browse files
authored
Merge pull request #13758 from TakeASwing-420/dev
Update index.md of Merkle-Patricia Trie doc
2 parents 9052495 + 095523e commit a09b7d0

File tree

1 file changed

+15
-15
lines changed
  • public/content/developers/docs/data-structures-and-encoding/patricia-merkle-trie

1 file changed

+15
-15
lines changed

public/content/developers/docs/data-structures-and-encoding/patricia-merkle-trie/index.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,33 @@ There is a difference between looking something up in the 'trie' and the underly
3434
The update and delete operations for radix tries can be defined as follows:
3535

3636
```
37-
def update(node,path,value):
38-
curnode = db.get(node) if node else [ NULL ] * 17
37+
def update(node_hash, path, value):
38+
curnode = db.get(node_hash) if node_hash else [ NULL ] * 17
3939
newnode = curnode.copy()
4040
if path == '':
4141
newnode[-1] = value
4242
else:
43-
newindex = update(curnode[path[0]],path[1:],value)
43+
newindex = update(curnode[path[0]], path[1:], value)
4444
newnode[path[0]] = newindex
45-
db.put(hash(newnode),newnode)
45+
db.put(hash(newnode), newnode)
4646
return hash(newnode)
4747
48-
def delete(node,path):
49-
if node is NULL:
48+
def delete(node_hash, path):
49+
if node_hash is NULL:
5050
return NULL
5151
else:
52-
curnode = db.get(node)
52+
curnode = db.get(node_hash)
5353
newnode = curnode.copy()
5454
if path == '':
5555
newnode[-1] = NULL
5656
else:
57-
newindex = delete(curnode[path[0]],path[1:])
57+
newindex = delete(curnode[path[0]], path[1:])
5858
newnode[path[0]] = newindex
5959
6060
if all(x is NULL for x in newnode):
6161
return NULL
6262
else:
63-
db.put(hash(newnode),newnode)
63+
db.put(hash(newnode), newnode)
6464
return hash(newnode)
6565
```
6666

@@ -137,10 +137,10 @@ Examples:
137137
Here is the extended code for getting a node in the Merkle Patricia trie:
138138

139139
```
140-
def get_helper(node,path):
141-
if path == []: return node
142-
if node = '': return ''
143-
curnode = rlp.decode(node if len(node) < 32 else db.get(node))
140+
def get_helper(node_hash,path):
141+
if path == []: return node_hash
142+
if node_hash == '': return ''
143+
curnode = rlp.decode(node_hash if len(node_hash) < 32 else db.get(node_hash))
144144
if len(curnode) == 2:
145145
(k2, v2) = curnode
146146
k2 = compact_decode(k2)
@@ -151,13 +151,13 @@ Here is the extended code for getting a node in the Merkle Patricia trie:
151151
elif len(curnode) == 17:
152152
return get_helper(curnode[path[0]],path[1:])
153153
154-
def get(node,path):
154+
def get(node_hash,path):
155155
path2 = []
156156
for i in range(len(path)):
157157
path2.push(int(ord(path[i]) / 16))
158158
path2.push(ord(path[i]) % 16)
159159
path2.push(16)
160-
return get_helper(node,path2)
160+
return get_helper(node_hash,path2)
161161
```
162162

163163
### Example Trie {#example-trie}

0 commit comments

Comments
 (0)