aboutsummaryrefslogtreecommitdiffstats
path: root/ethdb
diff options
context:
space:
mode:
authorJanos Guljas <janos@resenje.org>2018-02-09 19:23:30 +0800
committerJanos Guljas <janos@resenje.org>2018-02-22 21:23:17 +0800
commita3a07350dcef0ba39829a20d8ddba4bd3463d293 (patch)
tree100f2515cadd92105537a12e6981fab2193435ee /ethdb
parent820cf09c98706f71d4b02b6c25e62db15830f3fb (diff)
parent1a4e68721a901e86322631fed1191025a6d14c52 (diff)
downloaddexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar.gz
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar.bz2
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar.lz
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar.xz
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar.zst
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.zip
swarm, cmd/swarm: Merge branch 'master' into multiple-ens-endpoints
Diffstat (limited to 'ethdb')
-rw-r--r--ethdb/database.go9
-rw-r--r--ethdb/interface.go2
-rw-r--r--ethdb/memory_database.go21
3 files changed, 24 insertions, 8 deletions
diff --git a/ethdb/database.go b/ethdb/database.go
index 93755dd7e..d86585f07 100644
--- a/ethdb/database.go
+++ b/ethdb/database.go
@@ -299,6 +299,11 @@ func (b *ldbBatch) ValueSize() int {
return b.size
}
+func (b *ldbBatch) Reset() {
+ b.b.Reset()
+ b.size = 0
+}
+
type table struct {
db Database
prefix string
@@ -358,3 +363,7 @@ func (tb *tableBatch) Write() error {
func (tb *tableBatch) ValueSize() int {
return tb.batch.ValueSize()
}
+
+func (tb *tableBatch) Reset() {
+ tb.batch.Reset()
+}
diff --git a/ethdb/interface.go b/ethdb/interface.go
index 99a5b770d..537312003 100644
--- a/ethdb/interface.go
+++ b/ethdb/interface.go
@@ -41,4 +41,6 @@ type Batch interface {
Putter
ValueSize() int // amount of data in the batch
Write() error
+ // Reset resets the batch for reuse
+ Reset()
}
diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go
index 699bd0c9f..8efd7bf84 100644
--- a/ethdb/memory_database.go
+++ b/ethdb/memory_database.go
@@ -37,6 +37,12 @@ func NewMemDatabase() (*MemDatabase, error) {
}, nil
}
+func NewMemDatabaseWithCap(size int) (*MemDatabase, error) {
+ return &MemDatabase{
+ db: make(map[string][]byte, size),
+ }, nil
+}
+
func (db *MemDatabase) Put(key []byte, value []byte) error {
db.lock.Lock()
defer db.lock.Unlock()
@@ -74,14 +80,6 @@ func (db *MemDatabase) Keys() [][]byte {
return keys
}
-/*
-func (db *MemDatabase) GetKeys() []*common.Key {
- data, _ := db.Get([]byte("KeyRing"))
-
- return []*common.Key{common.NewKeyFromBytes(data)}
-}
-*/
-
func (db *MemDatabase) Delete(key []byte) error {
db.lock.Lock()
defer db.lock.Unlock()
@@ -96,6 +94,8 @@ func (db *MemDatabase) NewBatch() Batch {
return &memBatch{db: db}
}
+func (db *MemDatabase) Len() int { return len(db.db) }
+
type kv struct{ k, v []byte }
type memBatch struct {
@@ -123,3 +123,8 @@ func (b *memBatch) Write() error {
func (b *memBatch) ValueSize() int {
return b.size
}
+
+func (b *memBatch) Reset() {
+ b.writes = b.writes[:0]
+ b.size = 0
+}