@@ -34,33 +34,33 @@ There is a difference between looking something up in the 'trie' and the underly
34
34
The update and delete operations for radix tries can be defined as follows:
35
35
36
36
```
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
39
39
newnode = curnode.copy()
40
40
if path == '':
41
41
newnode[-1] = value
42
42
else:
43
- newindex = update(curnode[path[0]],path[1:],value)
43
+ newindex = update(curnode[path[0]], path[1:], value)
44
44
newnode[path[0]] = newindex
45
- db.put(hash(newnode),newnode)
45
+ db.put(hash(newnode), newnode)
46
46
return hash(newnode)
47
47
48
- def delete(node, path):
49
- if node is NULL:
48
+ def delete(node_hash, path):
49
+ if node_hash is NULL:
50
50
return NULL
51
51
else:
52
- curnode = db.get(node )
52
+ curnode = db.get(node_hash )
53
53
newnode = curnode.copy()
54
54
if path == '':
55
55
newnode[-1] = NULL
56
56
else:
57
- newindex = delete(curnode[path[0]],path[1:])
57
+ newindex = delete(curnode[path[0]], path[1:])
58
58
newnode[path[0]] = newindex
59
59
60
60
if all(x is NULL for x in newnode):
61
61
return NULL
62
62
else:
63
- db.put(hash(newnode),newnode)
63
+ db.put(hash(newnode), newnode)
64
64
return hash(newnode)
65
65
```
66
66
@@ -137,10 +137,10 @@ Examples:
137
137
Here is the extended code for getting a node in the Merkle Patricia trie:
138
138
139
139
```
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 ))
144
144
if len(curnode) == 2:
145
145
(k2, v2) = curnode
146
146
k2 = compact_decode(k2)
@@ -151,13 +151,13 @@ Here is the extended code for getting a node in the Merkle Patricia trie:
151
151
elif len(curnode) == 17:
152
152
return get_helper(curnode[path[0]],path[1:])
153
153
154
- def get(node ,path):
154
+ def get(node_hash ,path):
155
155
path2 = []
156
156
for i in range(len(path)):
157
157
path2.push(int(ord(path[i]) / 16))
158
158
path2.push(ord(path[i]) % 16)
159
159
path2.push(16)
160
- return get_helper(node ,path2)
160
+ return get_helper(node_hash ,path2)
161
161
```
162
162
163
163
### Example Trie {#example-trie}
0 commit comments