github.com/klaytn/klaytn@v1.12.1/storage/database/iterator.go (about)

     1  // Copyright 2018 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // This file is derived from ethdb/interface.go (2020/05/20).
    18  // Modified and improved for the klaytn development.
    19  
    20  package database
    21  
    22  // Iterator iterates over a database's key/value pairs in ascending key order.
    23  //
    24  // When it encounters an error any seek will return false and will yield no key/
    25  // value pairs. The error can be queried by calling the Error method. Calling
    26  // Release is still necessary.
    27  //
    28  // An iterator must be released after use, but it is not necessary to read an
    29  // iterator until exhaustion. An iterator is not safe for concurrent use, but it
    30  // is safe to use multiple iterators concurrently.
    31  type Iterator interface {
    32  	// Next moves the iterator to the next key/value pair. It returns whether the
    33  	// iterator is exhausted.
    34  	Next() bool
    35  
    36  	// Error returns any accumulated error. Exhausting all the key/value pairs
    37  	// is not considered to be an error.
    38  	Error() error
    39  
    40  	// Key returns the key of the current key/value pair, or nil if done. The caller
    41  	// should not modify the contents of the returned slice, and its contents may
    42  	// change on the next call to Next.
    43  	Key() []byte
    44  
    45  	// Value returns the value of the current key/value pair, or nil if done. The
    46  	// caller should not modify the contents of the returned slice, and its contents
    47  	// may change on the next call to Next.
    48  	Value() []byte
    49  
    50  	// Release releases associated resources. Release should always succeed and can
    51  	// be called multiple times without causing error.
    52  	Release()
    53  }
    54  
    55  // Iteratee wraps the NewIterator methods of a backing data store.
    56  type Iteratee interface {
    57  	// NewIterator creates a binary-alphabetical iterator over a subset
    58  	// of database content with a particular key prefix, starting at a particular
    59  	// initial key (or after, if it does not exist).
    60  	//
    61  	// Note: This method assumes that the prefix is NOT part of the start, so there's
    62  	// no need for the caller to prepend the prefix to the start
    63  	NewIterator(prefix []byte, start []byte) Iterator
    64  }