iterator

package
v0.0.0-...-3976360 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Next

func Next(it Iterator) bool

Next moves iterator to next if it is valid, otherwise move to its first.

Types

type Direction

type Direction int

Direction defines direction of iterator.

const (
	// Forward states that iterator is in forward iterating.
	Forward Direction = iota
	// Reverse states that iterator is in backward iterating.
	Reverse
)

type Iterator

type Iterator interface {
	// Next moves to next entry. It returns whether such entry exists.
	// The behaviour is undefined if current status of iterator is invalid.
	Next() bool

	// Prev moves to previous entry. It returns whether such entry exists.
	// The behaviour is undefined if current status of iterator is invalid.
	Prev() bool

	// First moves to the first entry. It returns whether such entry exists.
	First() bool

	// Last moves to the last entry. It returns whether such entry exists.
	Last() bool

	// Seek moves the iterator to the first entry with key >= target.
	// It returns whether such entry exists.
	Seek(target []byte) bool

	// Valid returns whether the iterator is point to a valid entry.
	Valid() bool

	// Key returns the key of current entry. The behaviour is undefined if
	// current status of iterator is invalid.
	Key() []byte

	// Value returns the value of current entry. The behaviour is undefined
	// if current status of iterator is invalid.
	Value() []byte

	// Err returns error we encounters so far. Seek methods, First, Last and Seek may
	// clear this error.
	Err() error

	// Close releases any resources hold by this iterator, and returns
	// any error it encounters so far. The behaviour is undefined if you
	// call any methods after this iterator has been closed.
	Close() error
}

Iterator has same method set as the exported one, but with fewer safety guarantees. The exported interface is a superset of internal one. Not all internal iterators can be safely exported to clients. Internal functions can't specify exported interface in their signature. Callers should be aware of this fact, and don't call any method that may lead to undefined behaviours.

func Empty

func Empty() Iterator

Empty returns an empty iterator.

This empty iterator has following properties: * First/Last/Seek/Valid return false. * Next/Prev/Key/Value panic. * Err/Close return nil.

func Error

func Error(err error) Iterator

Error returns an error iterator.

This error iterator has following properties: * First/Last/Seek/Valid return false. * Next/Prev/Key/Value panic. * Err/Close return the specified err.

func NewIndexIterator

func NewIndexIterator(index Iterator, blockf func([]byte) Iterator) Iterator

func NewMergeIterator

func NewMergeIterator(cmp keys.Comparer, iterators ...Iterator) Iterator

NewMergeIterator creates a iterator merging all entries from iterators. The resulting iterator implements semantics the exported Iterator interface defines. This means that if Next/Prev is the first seek method called, they act as First/Last respectively. If equal keys exist in different iterators, it is undefined and hence unstable which entry is retrieved first among different iterations.

func NewRangeIterator

func NewRangeIterator(start, limit []byte, cmp keys.Comparer, it Iterator) Iterator

NewRangeIterator creates a range iterator for keys in range [start, limit). Nil or empty start or limit act as no limitation in corresponding end. The resulting iterator implements semantics the exported Iterator interface defines. This means that if Next/Prev is the first seek method called, they act as First/Last respectively.

func WithCleanup

func WithCleanup(iterator Iterator, cleanup func() error) Iterator

type Status

type Status int

Status defines statuses for iterator.

const (
	// Initial is the initial status of iterator.
	Initial Status = iota
	// Invalid specifies that iterator encounters an error which can be
	// retrieved through Err().
	Invalid
	// Closed specifies that iterator has been closed.
	Closed
	// Valid specifies that iterator has entry retrieved in its Key/Value.
	Valid
)

Jump to

Keyboard shortcuts

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