mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 21:17:16 +00:00
916a1f8b83
* resetIH from scratch if needed * lmdb * add AbstractKV to loader, added new Object accessor around AbstractKV * add lmdb cli flag * add requirement of k!=nil on error in docs * add Size method for compatibility * read after put tests * fix multiput nils * simplify loops * increase mmap size * better error messages * better error messages * fix tests * better error messages * cleanup * avoid bolt usage in test * move hardcoded bucket name to dbutils * register more buckets * register more buckets * fix test
82 lines
1.4 KiB
Go
82 lines
1.4 KiB
Go
package ethdb
|
|
|
|
type puts struct {
|
|
mp map[string]putsBucket //map[dbi]putsBucket
|
|
size int
|
|
len int
|
|
}
|
|
|
|
func newPuts() *puts {
|
|
return &puts{
|
|
mp: make(map[string]putsBucket),
|
|
}
|
|
}
|
|
|
|
func (p *puts) set(bucket, key, value []byte) {
|
|
var bucketPuts putsBucket
|
|
var ok bool
|
|
if bucketPuts, ok = p.mp[string(bucket)]; !ok {
|
|
bucketPuts = make(putsBucket)
|
|
p.mp[string(bucket)] = bucketPuts
|
|
}
|
|
oldLen := len(bucketPuts)
|
|
skey := string(key)
|
|
if oldVal, ok := bucketPuts[skey]; ok {
|
|
p.size -= len(oldVal)
|
|
} else {
|
|
p.size += len(skey) + 32 // Add fixed overhead per key
|
|
}
|
|
bucketPuts[skey] = value
|
|
p.size += len(value)
|
|
p.len += len(bucketPuts) - oldLen
|
|
}
|
|
|
|
func (p *puts) get(bucket, key []byte) ([]byte, bool) {
|
|
var bucketPuts putsBucket
|
|
var ok bool
|
|
if bucketPuts, ok = p.mp[string(bucket)]; !ok {
|
|
return nil, false
|
|
}
|
|
return bucketPuts.Get(key)
|
|
}
|
|
|
|
func (p *puts) Delete(bucket, key []byte) {
|
|
p.set(bucket, key, nil)
|
|
}
|
|
|
|
func (p *puts) Len() int {
|
|
return p.len
|
|
}
|
|
|
|
func (p *puts) Size() int {
|
|
return p.size
|
|
}
|
|
|
|
type putsBucket map[string][]byte //map[key]value
|
|
|
|
func (pb putsBucket) Get(key []byte) ([]byte, bool) {
|
|
value, ok := pb[string(key)]
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
|
|
if value == nil {
|
|
return nil, true
|
|
}
|
|
|
|
return value, true
|
|
}
|
|
|
|
func (pb putsBucket) GetStr(key string) ([]byte, bool) {
|
|
value, ok := pb[key]
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
|
|
if value == nil {
|
|
return nil, true
|
|
}
|
|
|
|
return value, true
|
|
}
|