func (db *MemDB) Delete(key []byte) error {
	if len(key) == 0 {
		return tmdb.ErrKeyEmpty
	}
	db.mtx.Lock()
	defer db.mtx.Unlock()
	db.delete(key)
	return nil
}
Delete implements DB.
package memdb
import (
	"bytes"
	"fmt"
	"sync"
	"github.com/google/btree"
	tmdb "github.com/tendermint/tm-db"
)
const (
	bTreeDegree = 32
)
type item struct {
	key   []byte
	value []byte
}
func (i *item) Less(other btree.Item) bool {
	return bytes.Compare(i.key, other.(*item).key) == -1
}
func newKey(key []byte) *item {
	return &item{key: key}
}
func newPair(key, value []byte) *item {
	return &item{key: key, value: value}
}
type MemDB struct {
	mtx   sync.RWMutex
	btree *btree.BTree
}
var _ tmdb.DB = (*MemDB)(nil)
func NewDB() *MemDB {
	database := &MemDB{
		btree: btree.New(bTreeDegree),
	}
	return database
}
func (db *MemDB) Get(key []byte) ([]byte, error) {
	if len(key) == 0 {
		return nil, tmdb.ErrKeyEmpty
	}
	db.mtx.RLock()
	defer db.mtx.RUnlock()
	i := db.btree.Get(newKey(key))
	if i != nil {
		return i.(*item).value, nil
	}
	return nil, nil
}
func (db *MemDB) Has(key []byte) (bool, error) {
	if len(key) == 0 {
		return false, tmdb.ErrKeyEmpty
	}
	db.mtx.RLock()
	defer db.mtx.RUnlock()
	return db.btree.Has(newKey(key)), nil
}
func (db *MemDB) Set(key []byte, value []byte) error {
	if len(key) == 0 {
		return tmdb.ErrKeyEmpty
	}
	if value == nil {
		return tmdb.ErrValueNil
	}
	db.mtx.Lock()
	defer db.mtx.Unlock()
	db.set(key, value)
	return nil
}
func (db *MemDB) set(key []byte, value []byte) {
	db.btree.ReplaceOrInsert(newPair(key, value))
}
func (db *MemDB) SetSync(key []byte, value []byte) error {
	return db.Set(key, value)
}