Skip to content

Commit 539f809

Browse files
committed
trie: rename
1 parent bdcaad1 commit 539f809

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

trie/stacktrie.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ var stPool = sync.Pool{
4040
// so that callers can flush nodes into database with desired scheme.
4141
type NodeWriteFunc = func(owner common.Hash, path []byte, hash common.Hash, blob []byte)
4242

43-
func stackTrieFromPool(writer NodeWriteFunc, owner common.Hash) *StackTrie {
43+
func stackTrieFromPool(writeFn NodeWriteFunc, owner common.Hash) *StackTrie {
4444
st := stPool.Get().(*StackTrie)
4545
st.owner = owner
46-
st.writer = writer
46+
st.writeFn = writeFn
4747
return st
4848
}
4949

@@ -61,36 +61,36 @@ type StackTrie struct {
6161
val []byte // value contained by this node if it's a leaf
6262
key []byte // key chunk covered by this (leaf|ext) node
6363
children [16]*StackTrie // list of children (for branch and exts)
64-
writer NodeWriteFunc // function for committing nodes, can be nil
64+
writeFn NodeWriteFunc // function for committing nodes, can be nil
6565
}
6666

6767
// NewStackTrie allocates and initializes an empty trie.
68-
func NewStackTrie(writer NodeWriteFunc) *StackTrie {
68+
func NewStackTrie(writeFn NodeWriteFunc) *StackTrie {
6969
return &StackTrie{
7070
nodeType: emptyNode,
71-
writer: writer,
71+
writeFn: writeFn,
7272
}
7373
}
7474

7575
// NewStackTrieWithOwner allocates and initializes an empty trie, but with
7676
// the additional owner field.
77-
func NewStackTrieWithOwner(writer NodeWriteFunc, owner common.Hash) *StackTrie {
77+
func NewStackTrieWithOwner(writeFn NodeWriteFunc, owner common.Hash) *StackTrie {
7878
return &StackTrie{
7979
owner: owner,
8080
nodeType: emptyNode,
81-
writer: writer,
81+
writeFn: writeFn,
8282
}
8383
}
8484

8585
// NewFromBinary initialises a serialized stacktrie with the given db.
86-
func NewFromBinary(data []byte, writer NodeWriteFunc) (*StackTrie, error) {
86+
func NewFromBinary(data []byte, writeFn NodeWriteFunc) (*StackTrie, error) {
8787
var st StackTrie
8888
if err := st.UnmarshalBinary(data); err != nil {
8989
return nil, err
9090
}
9191
// If a database is used, we need to recursively add it to every child
92-
if writer != nil {
93-
st.setWriter(writer)
92+
if writeFn != nil {
93+
st.setWriter(writeFn)
9494
}
9595
return &st, nil
9696
}
@@ -163,25 +163,25 @@ func (st *StackTrie) unmarshalBinary(r io.Reader) error {
163163
return nil
164164
}
165165

166-
func (st *StackTrie) setWriter(writer NodeWriteFunc) {
167-
st.writer = writer
166+
func (st *StackTrie) setWriter(writeFn NodeWriteFunc) {
167+
st.writeFn = writeFn
168168
for _, child := range st.children {
169169
if child != nil {
170-
child.setWriter(writer)
170+
child.setWriter(writeFn)
171171
}
172172
}
173173
}
174174

175-
func newLeaf(owner common.Hash, key, val []byte, writer NodeWriteFunc) *StackTrie {
176-
st := stackTrieFromPool(writer, owner)
175+
func newLeaf(owner common.Hash, key, val []byte, writeFn NodeWriteFunc) *StackTrie {
176+
st := stackTrieFromPool(writeFn, owner)
177177
st.nodeType = leafNode
178178
st.key = append(st.key, key...)
179179
st.val = val
180180
return st
181181
}
182182

183-
func newExt(owner common.Hash, key []byte, child *StackTrie, writer NodeWriteFunc) *StackTrie {
184-
st := stackTrieFromPool(writer, owner)
183+
func newExt(owner common.Hash, key []byte, child *StackTrie, writeFn NodeWriteFunc) *StackTrie {
184+
st := stackTrieFromPool(writeFn, owner)
185185
st.nodeType = extNode
186186
st.key = append(st.key, key...)
187187
st.children[0] = child
@@ -215,7 +215,7 @@ func (st *StackTrie) Update(key, value []byte) {
215215

216216
func (st *StackTrie) Reset() {
217217
st.owner = common.Hash{}
218-
st.writer = nil
218+
st.writeFn = nil
219219
st.key = st.key[:0]
220220
st.val = nil
221221
for i := range st.children {
@@ -255,7 +255,7 @@ func (st *StackTrie) insert(key, value []byte, prefix []byte) {
255255

256256
// Add new child
257257
if st.children[idx] == nil {
258-
st.children[idx] = newLeaf(st.owner, key[1:], value, st.writer)
258+
st.children[idx] = newLeaf(st.owner, key[1:], value, st.writeFn)
259259
} else {
260260
st.children[idx].insert(key[1:], value, append(prefix, key[0]))
261261
}
@@ -284,7 +284,7 @@ func (st *StackTrie) insert(key, value []byte, prefix []byte) {
284284
// Break on the non-last byte, insert an intermediate
285285
// extension. The path prefix of the newly-inserted
286286
// extension should also contain the different byte.
287-
n = newExt(st.owner, st.key[diffidx+1:], st.children[0], st.writer)
287+
n = newExt(st.owner, st.key[diffidx+1:], st.children[0], st.writeFn)
288288
n.hash(append(prefix, st.key[:diffidx+1]...))
289289
} else {
290290
// Break on the last byte, no need to insert
@@ -306,12 +306,12 @@ func (st *StackTrie) insert(key, value []byte, prefix []byte) {
306306
// the common prefix is at least one byte
307307
// long, insert a new intermediate branch
308308
// node.
309-
st.children[0] = stackTrieFromPool(st.writer, st.owner)
309+
st.children[0] = stackTrieFromPool(st.writeFn, st.owner)
310310
st.children[0].nodeType = branchNode
311311
p = st.children[0]
312312
}
313313
// Create a leaf for the inserted part
314-
o := newLeaf(st.owner, key[diffidx+1:], value, st.writer)
314+
o := newLeaf(st.owner, key[diffidx+1:], value, st.writeFn)
315315

316316
// Insert both child leaves where they belong:
317317
origIdx := st.key[diffidx]
@@ -347,7 +347,7 @@ func (st *StackTrie) insert(key, value []byte, prefix []byte) {
347347
// Convert current node into an ext,
348348
// and insert a child branch node.
349349
st.nodeType = extNode
350-
st.children[0] = NewStackTrieWithOwner(st.writer, st.owner)
350+
st.children[0] = NewStackTrieWithOwner(st.writeFn, st.owner)
351351
st.children[0].nodeType = branchNode
352352
p = st.children[0]
353353
}
@@ -356,11 +356,11 @@ func (st *StackTrie) insert(key, value []byte, prefix []byte) {
356356
// value and another containing the new value. The child leaf
357357
// is hashed directly in order to free up some memory.
358358
origIdx := st.key[diffidx]
359-
p.children[origIdx] = newLeaf(st.owner, st.key[diffidx+1:], st.val, st.writer)
359+
p.children[origIdx] = newLeaf(st.owner, st.key[diffidx+1:], st.val, st.writeFn)
360360
p.children[origIdx].hash(append(prefix, st.key[:diffidx+1]...))
361361

362362
newIdx := key[diffidx]
363-
p.children[newIdx] = newLeaf(st.owner, key[diffidx+1:], value, st.writer)
363+
p.children[newIdx] = newLeaf(st.owner, key[diffidx+1:], value, st.writeFn)
364364

365365
// Finally, cut off the key part that has been passed
366366
// over to the children.
@@ -472,8 +472,8 @@ func (st *StackTrie) hashRec(hasher *hasher, path []byte) {
472472
// Write the hash to the 'val'. We allocate a new val here to not mutate
473473
// input values
474474
st.val = hasher.hashData(encodedNode)
475-
if st.writer != nil {
476-
st.writer(st.owner, path, common.BytesToHash(st.val), encodedNode)
475+
if st.writeFn != nil {
476+
st.writeFn(st.owner, path, common.BytesToHash(st.val), encodedNode)
477477
}
478478
}
479479

@@ -504,7 +504,7 @@ func (st *StackTrie) Hash() (h common.Hash) {
504504
// The associated database is expected, otherwise the whole commit
505505
// functionality should be disabled.
506506
func (st *StackTrie) Commit() (h common.Hash, err error) {
507-
if st.writer == nil {
507+
if st.writeFn == nil {
508508
return common.Hash{}, ErrCommitDisabled
509509
}
510510
hasher := newHasher(false)
@@ -522,6 +522,6 @@ func (st *StackTrie) Commit() (h common.Hash, err error) {
522522
hasher.sha.Write(st.val)
523523
hasher.sha.Read(h[:])
524524

525-
st.writer(st.owner, nil, h, st.val)
525+
st.writeFn(st.owner, nil, h, st.val)
526526
return h, nil
527527
}

0 commit comments

Comments
 (0)