iterator

package
v1.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: Apache-2.0, BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package iterator provides interface and implementation to traverse over contents of a database.

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Array

type Array interface {
	BasicArray

	// Index returns key/value pair with index of i.
	Index(i int) (key, value []byte)
}

Array is the interface that wraps BasicArray and basic Index method.

type ArrayIndexer

type ArrayIndexer interface {
	BasicArray

	// Get returns a new data iterator with index of i.
	Get(i int) Iterator
}

Array is the interface that wraps BasicArray and basic Get method.

type BasicArray

type BasicArray interface {
	// Len returns length of the array.
	Len() int

	// Search finds smallest index that point to a key that is greater
	// than or equal to the given key.
	Search(key []byte) int
}

BasicArray is the interface that wraps basic Len and Search method.

type CommonIterator

type CommonIterator interface {
	IteratorSeeker

	// util.Releaser is the interface that wraps basic Release method.
	// When called Release will releases any resources associated with the
	// iterator.
	util.Releaser

	// util.ReleaseSetter is the interface that wraps the basic SetReleaser
	// method.
	util.ReleaseSetter

	// TODO: Remove this when ready.
	Valid() bool

	// Error returns any accumulated error. Exhausting all the key/value pairs
	// is not considered to be an error.
	Error() error
}

CommonIterator is the interface that wraps common iterator methods.

type ErrorCallbackSetter

type ErrorCallbackSetter interface {
	// SetErrorCallback allows set an error callback of the corresponding
	// iterator. Use nil to clear the callback.
	SetErrorCallback(f func(err error))
}

ErrorCallbackSetter is the interface that wraps basic SetErrorCallback method.

ErrorCallbackSetter implemented by indexed and merged iterator.

type Iterator

type Iterator interface {
	CommonIterator

	// Key returns the key of the current key/value pair, or nil if done.
	// The caller should not modify the contents of the returned slice, and
	// its contents may change on the next call to any 'seeks method'.
	Key() []byte

	// Value returns the key of the current key/value pair, or nil if done.
	// The caller should not modify the contents of the returned slice, and
	// its contents may change on the next call to any 'seeks method'.
	Value() []byte
}

Iterator iterates over a DB's key/value pairs in key order.

When encounter an error any 'seeks method' will return false and will yield no key/value pairs. The error can be queried by calling the Error method. Calling Release is still necessary.

An iterator must be released after use, but it is not necessary to read an iterator until exhaustion. Also, an iterator is not necessarily safe for concurrent use, but it is safe to use multiple iterators concurrently, with each in a dedicated goroutine.

func NewArrayIterator

func NewArrayIterator(array Array) Iterator

NewArrayIterator returns an iterator from the given array.

func NewEmptyIterator

func NewEmptyIterator(err error) Iterator

NewEmptyIterator creates an empty iterator. The err parameter can be nil, but if not nil the given err will be returned by Error method.

func NewIndexedIterator

func NewIndexedIterator(index IteratorIndexer, strict bool) Iterator

NewIndexedIterator returns an 'indexed iterator'. An index is iterator that returns another iterator, a 'data iterator'. A 'data iterator' is the iterator that contains actual key/value pairs.

If strict is true the any 'corruption errors' (i.e errors.IsCorrupted(err) == true) won't be ignored and will halt 'indexed iterator', otherwise the iterator will continue to the next 'data iterator'. Corruption on 'index iterator' will not be ignored and will halt the iterator.

func NewMergedIterator

func NewMergedIterator(iters []Iterator, cmp comparer.Comparer, strict bool) Iterator

NewMergedIterator returns an iterator that merges its input. Walking the resultant iterator will return all key/value pairs of all input iterators in strictly increasing key order, as defined by cmp. The input's key ranges may overlap, but there are assumed to be no duplicate keys: if iters[i] contains a key k then iters[j] will not contain that key k. None of the iters may be nil.

If strict is true the any 'corruption errors' (i.e errors.IsCorrupted(err) == true) won't be ignored and will halt 'merged iterator', otherwise the iterator will continue to the next 'input iterator'.

type IteratorIndexer

type IteratorIndexer interface {
	CommonIterator

	// Get returns a new data iterator for the current position, or nil if
	// done.
	Get() Iterator
}

IteratorIndexer is the interface that wraps CommonIterator and basic Get method. IteratorIndexer provides index for indexed iterator.

func NewArrayIndexer

func NewArrayIndexer(array ArrayIndexer) IteratorIndexer

NewArrayIndexer returns an index iterator from the given array.

type IteratorSeeker

type IteratorSeeker interface {
	// First moves the iterator to the first key/value pair. If the iterator
	// only contains one key/value pair then First and Last would moves
	// to the same key/value pair.
	// It returns whether such pair exist.
	First() bool

	// Last moves the iterator to the last key/value pair. If the iterator
	// only contains one key/value pair then First and Last would moves
	// to the same key/value pair.
	// It returns whether such pair exist.
	Last() bool

	// Seek moves the iterator to the first key/value pair whose key is greater
	// than or equal to the given key.
	// It returns whether such pair exist.
	//
	// It is safe to modify the contents of the argument after Seek returns.
	Seek(key []byte) bool

	// Next moves the iterator to the next key/value pair.
	// It returns whether the iterator is exhausted.
	Next() bool

	// Prev moves the iterator to the previous key/value pair.
	// It returns whether the iterator is exhausted.
	Prev() bool
}

IteratorSeeker is the interface that wraps the 'seeks method'.

Jump to

Keyboard shortcuts

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