erigon-pulse/trie/utils.go
Igor Mandrigin 7fd4b0431b
refactor trie package a bit (#171)
* Refactor `structural*` files.

* some refactor

* dry hashbuilder a bit

* rename constants back to the magic rlp values
2019-11-15 17:50:16 +01:00

32 lines
520 B
Go

package trie
import "bytes"
type ByteArrayWriter struct {
dest []byte
pos int
}
func (w *ByteArrayWriter) Setup(dest []byte, pos int) {
w.dest = dest
w.pos = pos
}
func (w *ByteArrayWriter) Write(data []byte) (int, error) {
copy(w.dest[w.pos:], data)
w.pos += len(data)
return len(data), nil
}
type sortable [][]byte
func (s sortable) Len() int {
return len(s)
}
func (s sortable) Less(i, j int) bool {
return bytes.Compare(s[i], s[j]) < 0
}
func (s sortable) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}