Documentation ¶
Overview ¶
Package memdb provides in-memory key/value database implementation.
Index ¶
- Variables
- type DB
- func (p *DB) Capacity() int
- func (p *DB) Contains(key []byte) bool
- func (p *DB) Delete(key []byte) error
- func (p *DB) Find(key []byte) (rkey, value []byte, err error)
- func (p *DB) Free() int
- func (p *DB) Get(key []byte) (value []byte, err error)
- func (p *DB) Len() int
- func (p *DB) NewIterator(slice *util.Range) iterator.Iterator
- func (p *DB) Put(key []byte, value []byte) error
- func (p *DB) Reset()
- func (p *DB) Size() int
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.ErrNotFound ErrIterReleased = errors.New("leveldb/memdb: iterator released") )
Common errors.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is an in-memory key/value database.
func New ¶
func New(cmp comparer.BasicComparer, capacity int) *DB
New creates a new initialized in-memory key/value DB. The capacity is the initial key/value buffer capacity. The capacity is advisory, not enforced.
This DB is append-only, deleting an entry would remove entry node but not reclaim KV buffer.
The returned DB instance is safe for concurrent use.
func (*DB) Contains ¶
Contains returns true if the given key are in the DB.
It is safe to modify the contents of the arguments after Contains returns.
func (*DB) Delete ¶
Delete deletes the value for the given key. It returns ErrNotFound if the DB does not contain the key.
It is safe to modify the contents of the arguments after Delete returns.
func (*DB) Find ¶
Find finds key/value pair whose key is greater than or equal to the given key. It returns ErrNotFound if the table doesn't contain such pair.
The caller should not modify the contents of the returned slice, but it is safe to modify the contents of the argument after Find returns.
func (*DB) Get ¶
Get gets the value for the given key. It returns error.ErrNotFound if the DB does not contain the key.
The caller should not modify the contents of the returned slice, but it is safe to modify the contents of the argument after Get returns.
func (*DB) NewIterator ¶
NewIterator returns an iterator of the DB. The returned iterator is not safe for concurrent use, but it is safe to use multiple iterators concurrently, with each in a dedicated goroutine. It is also safe to use an iterator concurrently with modifying its underlying DB. However, the resultant key/value pairs are not guaranteed to be a consistent snapshot of the DB at a particular point in time.
Slice allows slicing the iterator to only contains keys in the given range. A nil Range.Start is treated as a key before all keys in the DB. And a nil Range.Limit is treated as a key after all keys in the DB.
WARNING: Any slice returned by interator (e.g. slice returned by calling Iterator.Key() or Iterator.Key() methods), its content should not be modified unless noted otherwise.
The iterator must be released after use, by calling Release method.
Also read Iterator documentation of the leveldb/iterator package.
func (*DB) Put ¶
Put sets the value for the given key. It overwrites any previous value for that key; a DB is not a multiple-map.
It is safe to modify the contents of the arguments after Put returns.