func (db *MemDatabase) Find(key []byte) Iterator {
	keys := make([][]byte, 0, len(db.db))
	for k := range db.db {
		if bytes.HasPrefix([]byte(k), key) {
			keys = append(keys, []byte(k))
		}
	}
	sort.Slice(keys, func(i, j int) bool {
		return string(keys[i]) < string(keys[j])
	})
	return &MemDatabaseIterator{
		keys:  keys,
		db:    db.db,
		index: -1,
	}
}
Find returns iterator iterating items with given key as prefix
package database
import (
	"bytes"
	"sort"
	"sync"
	"github.com/libonomy/libonomy-p2p/common/util"
)
type MemDatabase struct {
	db   map[string][]byte
	lock sync.RWMutex
}
func NewMemDatabase() *MemDatabase {
	return &MemDatabase{
		db: make(map[string][]byte),
	}
}
func (db *MemDatabase) Put(key []byte, value []byte) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	db.db[string(key)] = util.CopyBytes(value)
	return nil
}
func (db *MemDatabase) Has(key []byte) (bool, error) {
	db.lock.RLock()
	defer db.lock.RUnlock()
	_, ok := db.db[string(key)]
	return ok, nil
}
func (db *MemDatabase) Get(key []byte) ([]byte, error) {
	db.lock.RLock()
	defer db.lock.RUnlock()
	if entry, ok := db.db[string(key)]; ok {
		return util.CopyBytes(entry), nil
	}
	return nil, ErrNotFound
}
func (db *MemDatabase) Keys() [][]byte {
	db.lock.RLock()
	defer db.lock.RUnlock()
	keys := [][]byte{}
	for key := range db.db {
		keys = append(keys, []byte(key))
	}
	return keys
}
func (db *MemDatabase) Delete(key []byte) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	delete(db.db, string(key))
	return nil
}
func (db *MemDatabase) Close() {}
func (db *MemDatabase) NewBatch() Batch {
	return &memBatch{db: db}
}
func (db *MemDatabase) Len() int { return len(db.db) }
func (db *MemDatabase) NewMemDatabaseIterator() *MemDatabaseIterator {
	keys := make([][]byte, 0, len(db.db))
	for k := range db.db {
		keys = append(keys, []byte(k))
	}
	sort.Slice(keys, func(i, j int) bool {
		return string(keys[i]) < string(keys[j])
	})
	return &MemDatabaseIterator{
		keys:  keys,
		db:    db.db,
		index: -1,
	}
}
func (db *MemDatabase) Iterator() Iterator {
	return db.NewMemDatabaseIterator()
}