erigon-pulse/common/changeset/account_changeset.go
b00ris e8b617bbf2
Add sort.Search to account changeset (#671)
* fast search

* fix

* remove copy bytes
2020-06-16 15:03:35 +01:00

70 lines
1.6 KiB
Go

package changeset
import (
"github.com/ledgerwatch/turbo-geth/common"
)
/* Hashed changesets (key is a hash of common.Address) */
func NewAccountChangeSet() *ChangeSet {
return &ChangeSet{
Changes: make([]Change, 0),
keyLen: common.HashLength,
}
}
func EncodeAccounts(s *ChangeSet) ([]byte, error) {
return encodeAccounts(s)
}
func DecodeAccounts(b []byte) (*ChangeSet, error) {
h := NewAccountChangeSet()
err := decodeAccountsWithKeyLen(b, common.HashLength, h)
if err != nil {
return nil, err
}
return h, nil
}
type AccountChangeSetBytes []byte
func (b AccountChangeSetBytes) Walk(f func(k, v []byte) error) error {
return walkAccountChangeSet(b, common.HashLength, f)
}
func (b AccountChangeSetBytes) Find(k []byte) ([]byte, error) {
return findInAccountChangeSetBytes(b, k, common.HashLength)
}
/* Plain changesets (key is a common.Address) */
func NewAccountChangeSetPlain() *ChangeSet {
return &ChangeSet{
Changes: make([]Change, 0),
keyLen: common.AddressLength,
}
}
func EncodeAccountsPlain(s *ChangeSet) ([]byte, error) {
return encodeAccounts(s)
}
func DecodeAccountsPlain(b []byte) (*ChangeSet, error) {
h := NewAccountChangeSetPlain()
err := decodeAccountsWithKeyLen(b, common.AddressLength, h)
if err != nil {
return nil, err
}
return h, nil
}
type AccountChangeSetPlainBytes []byte
func (b AccountChangeSetPlainBytes) Walk(f func(k, v []byte) error) error {
return walkAccountChangeSet(b, common.AddressLength, f)
}
func (b AccountChangeSetPlainBytes) Find(k []byte) ([]byte, error) {
return findInAccountChangeSetBytes(b, k, common.AddressLength)
}