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 = util.ErrNotFound
)
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 initalized in-memory key/value DB. The capacity is the initial key/value buffer capacity. The capacity is advisory, not enforced.
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 goroutine-safe, 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.
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 multi-map.
It is safe to modify the contents of the arguments after Put returns.