2021-07-30 06:38:09 +00:00
|
|
|
package splitstore
|
|
|
|
|
|
|
|
import (
|
2022-01-25 15:29:02 +00:00
|
|
|
"sync"
|
|
|
|
|
2021-07-30 06:38:09 +00:00
|
|
|
cid "github.com/ipfs/go-cid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ObjectVisitor is an interface for deduplicating objects during walks
|
|
|
|
type ObjectVisitor interface {
|
|
|
|
Visit(cid.Cid) (bool, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type noopVisitor struct{}
|
|
|
|
|
|
|
|
var _ ObjectVisitor = (*noopVisitor)(nil)
|
|
|
|
|
|
|
|
func (v *noopVisitor) Visit(_ cid.Cid) (bool, error) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2022-01-25 15:29:02 +00:00
|
|
|
type tmpVisitor struct {
|
2021-07-30 06:38:09 +00:00
|
|
|
set *cid.Set
|
|
|
|
}
|
|
|
|
|
2022-01-25 15:29:02 +00:00
|
|
|
var _ ObjectVisitor = (*tmpVisitor)(nil)
|
2021-07-30 06:38:09 +00:00
|
|
|
|
2022-01-25 15:29:02 +00:00
|
|
|
func (v *tmpVisitor) Visit(c cid.Cid) (bool, error) {
|
2021-07-30 06:38:09 +00:00
|
|
|
return v.set.Visit(c), nil
|
|
|
|
}
|
2021-07-30 06:51:09 +00:00
|
|
|
|
2022-01-25 15:29:02 +00:00
|
|
|
func newTmpVisitor() ObjectVisitor {
|
|
|
|
return &tmpVisitor{set: cid.NewSet()}
|
|
|
|
}
|
|
|
|
|
|
|
|
type concurrentVisitor struct {
|
|
|
|
mx sync.Mutex
|
|
|
|
set *cid.Set
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ ObjectVisitor = (*concurrentVisitor)(nil)
|
|
|
|
|
|
|
|
func newConcurrentVisitor() *concurrentVisitor {
|
|
|
|
return &concurrentVisitor{set: cid.NewSet()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *concurrentVisitor) Visit(c cid.Cid) (bool, error) {
|
|
|
|
v.mx.Lock()
|
|
|
|
defer v.mx.Unlock()
|
|
|
|
|
|
|
|
return v.set.Visit(c), nil
|
2021-07-30 06:51:09 +00:00
|
|
|
}
|