forked from NethermindEth/juno
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.go
More file actions
46 lines (36 loc) · 1.63 KB
/
Copy pathiterator.go
File metadata and controls
46 lines (36 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package db
import "io"
// Provides functionality to iterate over a database's key/value pairs in ascending order.
// It must be closed after use. A single iterator cannot be used concurrently. Multiple iterators can be used
// concurrently.
type Iterator interface {
io.Closer
// Valid returns true if the iterator is positioned at a valid key/value pair.
Valid() bool
// First moves the iterator to the first key/value pair. Returns true
// if the iterator is pointing at a valid entry and false otherwise.
First() bool
// Prev moves the iterator to the previous key/value pair. Returns true
// if the iterator is pointing at a valid entry and false otherwise.
Prev() bool
// Next moves the iterator to the next key/value pair. It returns whether the
// iterator is valid after the call. Once invalid, the iterator remains
// invalid.
Next() bool
// Key returns the key at the current position.
Key() []byte
// Value returns the value at the current position.
Value() ([]byte, error)
// DO NOT USE this unless the value is consumed immediately.
//
// UncopiedValue returns the value at the current position without copying it.
// The returned slice is invalidated by the next call to [Next], [Prev], or [Seek].
// Callers must copy the value if it needs to outlive the current iteration.
//
// This is intended for immediate unmarshalling to avoid an extra allocation.
UncopiedValue() ([]byte, error)
// Seek would seek to the provided key if present. If absent, it would seek to the next
// key in lexicographical order. Returns true if the iterator is pointing at a valid entry
// and false otherwise.
Seek(key []byte) bool
}