memdb

package
v2.7.1-hack+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2019 License: GPL-3.0, BSD-2-Clause Imports: 6 Imported by: 10

Documentation

Overview

Package memdb provides in-memory key/value database implementation.

Index

Constants

This section is empty.

Variables

View Source
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 New2

func New2(cmp comparer.BasicComparer, capacity int) *DB

func (*DB) Capacity

func (p *DB) Capacity() int

Capacity returns keys/values buffer capacity.

func (*DB) Contains

func (p *DB) Contains(key []byte) bool

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) Copy

func (p *DB) Copy() *DB

func (*DB) Copy2

func (p *DB) Copy2(bytesGetter func(n int) []byte, intGetter func(n int) []int) *DB

func (*DB) Delete

func (p *DB) Delete(key []byte) error

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) Destroy2

func (p *DB) Destroy2(putter func(x interface{}))

func (*DB) Find

func (p *DB) Find(key []byte) (rkey, value []byte, err error)

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) Free

func (p *DB) Free() int

Free returns keys/values free buffer before need to grow.

func (*DB) Get

func (p *DB) Get(key []byte) (value []byte, err error)

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) Len

func (p *DB) Len() int

Len returns the number of entries in the DB.

func (*DB) NewIterator

func (p *DB) NewIterator(slice *util.Range) iterator.Iterator

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.

The iterator must be released after use, by calling Release method.

Also read Iterator documentation of the leveldb/iterator package.

func (*DB) Put

func (p *DB) Put(key []byte, value []byte) error

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.

func (*DB) Reset

func (p *DB) Reset()

Reset resets the DB to initial empty state. Allows reuse the buffer.

func (*DB) Size

func (p *DB) Size() int

Size returns sum of keys and values length. Note that deleted key/value will not be accounted for, but it will still consume the buffer, since the buffer is append only.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL