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