-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator.go
98 lines (76 loc) · 2.55 KB
/
iterator.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) 2020 Bert Young. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package leveldb
// An iterator yields a sequence of key/value pairs from a source.
// The following class defines the interface. Multiple implementations
// are provided by this library. In particular, iterators are provided
// to access the contents of a Table or a DB.
type Iterator interface {
// An iterator is either positioned at a key/value pair, or
// not valid. This method returns true iff the iterator is valid.
Valid() bool
// Position at the first key in the source. The iterator is Valid()
// after this call iff the source is not empty.
SeekToFirst()
// Position at the last key in the source. The iterator is
// Valid() after this call iff the source is not empty.
SeekToLast()
// Position at the first key in the source that at or past target
// The iterator is Valid() after this call iff the source contains
// an entry that comes at or past target.
Seek(target []byte)
// Moves to the next entry in the source. After this call, Valid() is
// true iff the iterator was not positioned at the last entry in the source.
// REQUIRES: Valid()
Next()
// Moves to the previous entry in the source. After this call, Valid() is
// true iff the iterator was not positioned at the first entry in source.
// REQUIRES: Valid()
Prev()
// Return the key for the current entry. The underlying storage for
// the returned slice is valid only until the next modification of
// the iterator.
// REQUIRES: Valid()
Key() []byte
// Return the value for the current entry. The underlying storage for
// the returned slice is valid only until the next modification of
// the iterator.
// REQUIRES: Valid()
Value() []byte
// If an error has occurred, return it. Else return an ok status.
Status() Status
}
type EmptyIterator struct {
state Status
}
// Return an empty iterator with the specified status.
func NewEmptyIterator(s Status) Iterator {
return &EmptyIterator{state: s}
}
func (_ *EmptyIterator) Valid() bool {
return false
}
func (_ *EmptyIterator) Seek([]byte) {
}
func (_ *EmptyIterator) SeekToFirst() {
}
func (_ *EmptyIterator) SeekToLast() {
}
func (_ *EmptyIterator) Prev() {
panic("Can't Prev")
}
func (_ *EmptyIterator) Next() {
panic("Can't Next")
}
func (_ *EmptyIterator) Key() []byte {
panic("Can't have key")
return nil
}
func (_ *EmptyIterator) Value() []byte {
panic("Can't have value")
return nil
}
func (i *EmptyIterator) Status() Status {
return i.state
}