table

package
v0.0.0-...-6b4daa5 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2016 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package table allows read and write sorted key/value.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.ErrNotFound
	ErrReaderReleased = errors.New("leveldb/table: reader released")
	ErrIterReleased   = errors.New("leveldb/table: iterator released")
)

Reader errors.

Functions

This section is empty.

Types

type ErrCorrupted

type ErrCorrupted struct {
	Pos    int64
	Size   int64
	Kind   string
	Reason string
}

ErrCorrupted describes error due to corruption. This error will be wrapped with errors.ErrCorrupted.

func (*ErrCorrupted) Error

func (e *ErrCorrupted) Error() string

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a table reader.

func NewReader

func NewReader(f io.ReaderAt, size int64, fd storage.FileDesc, cache *cache.NamespaceGetter, bpool *util.BufferPool, o *opt.Options) (*Reader, error)

NewReader creates a new initialized table reader for the file. The fi, cache and bpool is optional and can be nil.

The returned table reader instance is safe for concurrent use.

func (*Reader) Find

func (r *Reader) Find(key []byte, filtered bool, ro *opt.ReadOptions) (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. If filtered is true then the nearest 'block' will be checked against 'filter data' (if present) and will immediately return ErrNotFound if 'filter data' indicates that such pair doesn't exist.

The caller may modify the contents of the returned slice as it is its own copy. It is safe to modify the contents of the argument after Find returns.

func (*Reader) FindKey

func (r *Reader) FindKey(key []byte, filtered bool, ro *opt.ReadOptions) (rkey []byte, err error)

FindKey finds key that is greater than or equal to the given key. It returns ErrNotFound if the table doesn't contain such key. If filtered is true then the nearest 'block' will be checked against 'filter data' (if present) and will immediately return ErrNotFound if 'filter data' indicates that such key doesn't exist.

The caller may modify the contents of the returned slice as it is its own copy. It is safe to modify the contents of the argument after Find returns.

func (*Reader) Get

func (r *Reader) Get(key []byte, ro *opt.ReadOptions) (value []byte, err error)

Get gets the value for the given key. It returns errors.ErrNotFound if the table does not contain the key.

The caller may modify the contents of the returned slice as it is its own copy. It is safe to modify the contents of the argument after Find returns.

func (*Reader) NewIterator

func (r *Reader) NewIterator(slice *util.Range, ro *opt.ReadOptions) iterator.Iterator

NewIterator creates an iterator from the table.

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 table. And a nil Range.Limit is treated as a key after all keys in the table.

The returned iterator is not safe for concurrent use and should be released after use.

Also read Iterator documentation of the leveldb/iterator package.

func (*Reader) OffsetOf

func (r *Reader) OffsetOf(key []byte) (offset int64, err error)

OffsetOf returns approximate offset for the given key.

It is safe to modify the contents of the argument after Get returns.

func (*Reader) Release

func (r *Reader) Release()

Release implements util.Releaser. It also close the file if it is an io.Closer.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer is a table writer.

func NewWriter

func NewWriter(f io.Writer, o *opt.Options) *Writer

NewWriter creates a new initialized table writer for the file.

Table writer is not safe for concurrent use.

func (*Writer) Append

func (w *Writer) Append(key, value []byte) error

Append appends key/value pair to the table. The keys passed must be in increasing order.

It is safe to modify the contents of the arguments after Append returns.

func (*Writer) BlocksLen

func (w *Writer) BlocksLen() int

BlocksLen returns number of blocks written so far.

func (*Writer) BytesLen

func (w *Writer) BytesLen() int

BytesLen returns number of bytes written so far.

func (*Writer) Close

func (w *Writer) Close() error

Close will finalize the table. Calling Append is not possible after Close, but calling BlocksLen, EntriesLen and BytesLen is still possible.

func (*Writer) EntriesLen

func (w *Writer) EntriesLen() int

EntriesLen returns number of entries added so far.

Jump to

Keyboard shortcuts

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