-
Notifications
You must be signed in to change notification settings - Fork 36
/
types.go
51 lines (47 loc) · 1.2 KB
/
types.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
package fs2
type MultiMap interface {
Keys() (ItemIterator, error)
Values() (ItemIterator, error)
Iterate() (Iterator, error)
Backward() (Iterator, error)
Find(key []byte) (Iterator, error)
DoFind(key []byte, do func([]byte, []byte) error) error
Range(from, to []byte) (Iterator, error)
DoRange(from, to []byte, do func([]byte, []byte) error) error
Has(key []byte) (bool, error)
Count(key []byte) (int, error)
Add(key []byte, value []byte) error
Remove(key []byte, where func([]byte) bool) error
Size() int
}
type Iterator func() ([]byte, []byte, error, Iterator)
type ItemIterator func() ([]byte, error, ItemIterator)
func Do(run func() (Iterator, error), do func(key []byte, value []byte) error) error {
kvi, err := run()
if err != nil {
return err
}
var key []byte
var value []byte
for key, value, err, kvi = kvi(); kvi != nil; key, value, err, kvi = kvi() {
e := do(key, value)
if e != nil {
return e
}
}
return err
}
func DoItem(run func() (ItemIterator, error), do func([]byte) error) error {
it, err := run()
if err != nil {
return err
}
var item []byte
for item, err, it = it(); it != nil; item, err, it = it() {
e := do(item)
if e != nil {
return e
}
}
return err
}