mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
Update list_hasher.go
This commit is contained in:
parent
e578f61d89
commit
c1930b37cf
1 changed files with 8 additions and 11 deletions
|
|
@ -22,11 +22,12 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ListHasher is the wrapper of Merkle-Patricia-Trie, implementing the
|
// ListHasher is a wrapper of the Merkle-Patricia-Trie, which implements
|
||||||
// types.ListHasher by always deep-copying the supplied slices.
|
// types.ListHasher. Compared to a Trie instance, the Update method of this
|
||||||
|
// type always deep-copies its input slices.
|
||||||
//
|
//
|
||||||
// This implementation is very inefficient in terms of memory allocation
|
// This implementation is very inefficient in terms of memory allocation,
|
||||||
// compared with StackTrie, only for correctness comparison purpose.
|
// compared with StackTrie. It exists only for correctness comparison purposes.
|
||||||
type ListHasher struct {
|
type ListHasher struct {
|
||||||
tr *Trie
|
tr *Trie
|
||||||
}
|
}
|
||||||
|
|
@ -38,22 +39,18 @@ func NewListHasher() *ListHasher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset implements types.ListHasher, clearing the internal state and prepare
|
// Reset clears the internal state prepares the ListHasher for reuse.
|
||||||
// it for reuse.
|
|
||||||
func (h *ListHasher) Reset() {
|
func (h *ListHasher) Reset() {
|
||||||
h.tr.reset()
|
h.tr.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update implements types.ListHasher, inserting the given key-value pair into
|
// Update inserts a key-value pair into the trie.
|
||||||
// the trie. The supplied key-value pair should be deep-copied to satisfy the
|
|
||||||
// interface restriction.
|
|
||||||
func (h *ListHasher) Update(key []byte, value []byte) error {
|
func (h *ListHasher) Update(key []byte, value []byte) error {
|
||||||
key, value = bytes.Clone(key), bytes.Clone(value)
|
key, value = bytes.Clone(key), bytes.Clone(value)
|
||||||
return h.tr.Update(key, value)
|
return h.tr.Update(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash implements types.ListHasher, computing the final hash of all inserted
|
// Hash computes the root hash of all inserted key-value pairs.
|
||||||
// key-value pairs.
|
|
||||||
func (h *ListHasher) Hash() common.Hash {
|
func (h *ListHasher) Hash() common.Hash {
|
||||||
return h.tr.Hash()
|
return h.tr.Hash()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue