github.com/chain5j/chain5j-pkg@v1.0.7/database/kvstore/iterator.go (about)

     1  // Package kvstore
     2  //
     3  // @author: xwc1125
     4  package kvstore
     5  
     6  // Iterator iterates over a database's key/value pairs in ascending key order.
     7  //
     8  // When it encounters an error any seek will return false and will yield no key/
     9  // value pairs. The error can be queried by calling the Error method. Calling
    10  // Release is still necessary.
    11  //
    12  // An iterator must be released after use, but it is not necessary to read an
    13  // iterator until exhaustion. An iterator is not safe for concurrent use, but it
    14  // is safe to use multiple iterators concurrently.
    15  type Iterator interface {
    16  	// Next moves the iterator to the next key/value pair. It returns whether the
    17  	// iterator is exhausted.
    18  	Next() bool
    19  
    20  	// Error returns any accumulated error. Exhausting all the key/value pairs
    21  	// is not considered to be an error.
    22  	Error() error
    23  
    24  	// Key returns the key of the current key/value pair, or nil if done. The caller
    25  	// should not modify the contents of the returned slice, and its contents may
    26  	// change on the next call to Next.
    27  	Key() []byte
    28  
    29  	// Value returns the value of the current key/value pair, or nil if done. The
    30  	// caller should not modify the contents of the returned slice, and its contents
    31  	// may change on the next call to Next.
    32  	Value() []byte
    33  
    34  	// Release releases associated resources. Release should always succeed and can
    35  	// be called multiple times without causing error.
    36  	Release()
    37  }
    38  
    39  // Iteratee wraps the NewIterator methods of a backing data store.
    40  type Iteratee interface {
    41  	// NewIterator creates a binary-alphabetical iterator over the entire keyspace
    42  	// contained within the key-value database.
    43  	NewIterator() Iterator
    44  
    45  	// NewIteratorWithStart creates a binary-alphabetical iterator over a subset of
    46  	// database content starting at a particular initial key (or after, if it does
    47  	// not exist).
    48  	NewIteratorWithStart(start []byte) Iterator
    49  
    50  	// NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset
    51  	// of database content with a particular key prefix.
    52  	NewIteratorWithPrefix(prefix []byte) Iterator
    53  }