core, eth, ethdb, trie: simplify range proofs
This commit is contained in:
@ -25,9 +25,6 @@ const IdealBatchSize = 100 * 1024
|
||||
type Batch interface {
|
||||
KeyValueWriter
|
||||
|
||||
// KeyCount retrieves the number of keys queued up for writing.
|
||||
KeyCount() int
|
||||
|
||||
// ValueSize retrieves the amount of data queued up for writing.
|
||||
ValueSize() int
|
||||
|
||||
@ -47,3 +44,28 @@ type Batcher interface {
|
||||
// until a final write is called.
|
||||
NewBatch() Batch
|
||||
}
|
||||
|
||||
// HookedBatch wraps an arbitrary batch where each operation may be hooked into
|
||||
// to monitor from black box code.
|
||||
type HookedBatch struct {
|
||||
Batch
|
||||
|
||||
OnPut func(key []byte, value []byte) // Callback if a key is inserted
|
||||
OnDelete func(key []byte) // Callback if a key is deleted
|
||||
}
|
||||
|
||||
// Put inserts the given value into the key-value data store.
|
||||
func (b HookedBatch) Put(key []byte, value []byte) error {
|
||||
if b.OnPut != nil {
|
||||
b.OnPut(key, value)
|
||||
}
|
||||
return b.Batch.Put(key, value)
|
||||
}
|
||||
|
||||
// Delete removes the key from the key-value data store.
|
||||
func (b HookedBatch) Delete(key []byte) error {
|
||||
if b.OnDelete != nil {
|
||||
b.OnDelete(key)
|
||||
}
|
||||
return b.Batch.Delete(key)
|
||||
}
|
||||
|
@ -448,7 +448,6 @@ func (db *Database) meter(refresh time.Duration) {
|
||||
type batch struct {
|
||||
db *leveldb.DB
|
||||
b *leveldb.Batch
|
||||
keys int
|
||||
size int
|
||||
}
|
||||
|
||||
@ -462,16 +461,10 @@ func (b *batch) Put(key, value []byte) error {
|
||||
// Delete inserts the a key removal into the batch for later committing.
|
||||
func (b *batch) Delete(key []byte) error {
|
||||
b.b.Delete(key)
|
||||
b.keys++
|
||||
b.size += len(key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// KeyCount retrieves the number of keys queued up for writing.
|
||||
func (b *batch) KeyCount() int {
|
||||
return b.keys
|
||||
}
|
||||
|
||||
// ValueSize retrieves the amount of data queued up for writing.
|
||||
func (b *batch) ValueSize() int {
|
||||
return b.size
|
||||
@ -485,7 +478,7 @@ func (b *batch) Write() error {
|
||||
// Reset resets the batch for reuse.
|
||||
func (b *batch) Reset() {
|
||||
b.b.Reset()
|
||||
b.keys, b.size = 0, 0
|
||||
b.size = 0
|
||||
}
|
||||
|
||||
// Replay replays the batch contents.
|
||||
|
@ -198,7 +198,6 @@ type keyvalue struct {
|
||||
type batch struct {
|
||||
db *Database
|
||||
writes []keyvalue
|
||||
keys int
|
||||
size int
|
||||
}
|
||||
|
||||
@ -212,16 +211,10 @@ func (b *batch) Put(key, value []byte) error {
|
||||
// Delete inserts the a key removal into the batch for later committing.
|
||||
func (b *batch) Delete(key []byte) error {
|
||||
b.writes = append(b.writes, keyvalue{common.CopyBytes(key), nil, true})
|
||||
b.keys++
|
||||
b.size += len(key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// KeyCount retrieves the number of keys queued up for writing.
|
||||
func (b *batch) KeyCount() int {
|
||||
return b.keys
|
||||
}
|
||||
|
||||
// ValueSize retrieves the amount of data queued up for writing.
|
||||
func (b *batch) ValueSize() int {
|
||||
return b.size
|
||||
@ -245,7 +238,7 @@ func (b *batch) Write() error {
|
||||
// Reset resets the batch for reuse.
|
||||
func (b *batch) Reset() {
|
||||
b.writes = b.writes[:0]
|
||||
b.keys, b.size = 0, 0
|
||||
b.size = 0
|
||||
}
|
||||
|
||||
// Replay replays the batch contents.
|
||||
|
Reference in New Issue
Block a user