github.com/cryptotooltop/go-ethereum@v0.0.0-20231103184714-151d1922f3e5/trie/database_types.go (about) 1 package trie 2 3 import ( 4 "bytes" 5 "crypto/sha256" 6 "errors" 7 ) 8 9 // ErrNotFound is used by the implementations of the interface db.Storage for 10 // when a key is not found in the storage 11 var ErrNotFound = errors.New("key not found") 12 13 // KV contains a key (K) and a value (V) 14 type KV struct { 15 K []byte 16 V []byte 17 } 18 19 // KvMap is a key-value map between a sha256 byte array hash, and a KV struct 20 type KvMap map[[sha256.Size]byte]KV 21 22 // Get retreives the value respective to a key from the KvMap 23 func (m KvMap) Get(k []byte) ([]byte, bool) { 24 v, ok := m[sha256.Sum256(k)] 25 return v.V, ok 26 } 27 28 // Put stores a key and a value in the KvMap 29 func (m KvMap) Put(k, v []byte) { 30 m[sha256.Sum256(k)] = KV{k, v} 31 } 32 33 // Concat concatenates arrays of bytes 34 func Concat(vs ...[]byte) []byte { 35 var b bytes.Buffer 36 for _, v := range vs { 37 b.Write(v) 38 } 39 return b.Bytes() 40 } 41 42 // Clone clones a byte array into a new byte array 43 func Clone(b0 []byte) []byte { 44 b1 := make([]byte, len(b0)) 45 copy(b1, b0) 46 return b1 47 }