-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbset.go
48 lines (39 loc) · 1020 Bytes
/
dbset.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
package set
import (
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
"github.com/ipfs/go-ipfs/blocks/bloom"
"github.com/ipfs/go-ipfs/util"
)
type datastoreBlockSet struct {
dstore ds.Datastore
bset BlockSet
}
// NewDBWrapperSet returns a new blockset wrapping a given datastore
func NewDBWrapperSet(d ds.Datastore, bset BlockSet) BlockSet {
return &datastoreBlockSet{
dstore: d,
bset: bset,
}
}
func (d *datastoreBlockSet) AddBlock(k util.Key) {
err := d.dstore.Put(k.DsKey(), []byte{})
if err != nil {
log.Debugf("blockset put error: %s", err)
}
d.bset.AddBlock(k)
}
func (d *datastoreBlockSet) RemoveBlock(k util.Key) {
d.bset.RemoveBlock(k)
if !d.bset.HasKey(k) {
d.dstore.Delete(k.DsKey())
}
}
func (d *datastoreBlockSet) HasKey(k util.Key) bool {
return d.bset.HasKey(k)
}
func (d *datastoreBlockSet) GetBloomFilter() bloom.Filter {
return d.bset.GetBloomFilter()
}
func (d *datastoreBlockSet) GetKeys() []util.Key {
return d.bset.GetKeys()
}