1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00
Files
kubo/blocks/key/key_set.go
Jeromy da0d48e6c5 Add locking interface to blockstore
The addition of a locking interface to the blockstore allows us to
perform atomic operations on the underlying datastore without having to
worry about different operations happening in the background, such as
garbage collection.

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
2016-01-12 08:21:13 -08:00

40 lines
587 B
Go

package key
type KeySet interface {
Add(Key)
Has(Key) bool
Remove(Key)
Keys() []Key
}
type keySet struct {
keys map[Key]struct{}
}
func NewKeySet() KeySet {
return &keySet{make(map[Key]struct{})}
}
func (gcs *keySet) Add(k Key) {
gcs.keys[k] = struct{}{}
}
func (gcs *keySet) Has(k Key) bool {
_, has := gcs.keys[k]
return has
}
func (ks *keySet) Keys() []Key {
var out []Key
for k, _ := range ks.keys {
out = append(out, k)
}
return out
}
func (ks *keySet) Remove(k Key) {
delete(ks.keys, k)
}
// TODO: implement disk-backed keyset for working with massive DAGs