Skip to content

Commit

Permalink
s/BatchDAG/BufferedDAG
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Oct 26, 2018
1 parent c355441 commit e0a8834
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,35 @@ func MaxNodesBatchOption(num int) BatchOption {
// Batch implements DAGService using a Batch NodeAdder to wrap add
// operations in the given DAGService. It will trigger Commit() before any
// non-Add operations, but otherwise calling Commit() is left to the user.
type BatchDAG struct {
type BufferedDAG struct {
ds DAGService
b *Batch
}

func NewBatchDAG(ctx context.Context, ds DAGService, opts ...BatchOption) *BatchDAG {
return &BatchDAG{
func NewBufferedDAG(ctx context.Context, ds DAGService, opts ...BatchOption) *BufferedDAG {
return &BufferedDAG{
ds: ds,
b: NewBatch(ctx, ds, opts...),
}
}

// Commit calls commit on the Batch.
func (bd *BatchDAG) Commit() error {
func (bd *BufferedDAG) Commit() error {
return bd.b.Commit()
}

// Add adds a new node using Batch.
func (bd *BatchDAG) Add(ctx context.Context, n Node) error {
func (bd *BufferedDAG) Add(ctx context.Context, n Node) error {
return bd.b.Add(ctx, n)
}

// AddMany adds many nodes using Batch.
func (bd *BatchDAG) AddMany(ctx context.Context, nds []Node) error {
func (bd *BufferedDAG) AddMany(ctx context.Context, nds []Node) error {
return bd.b.AddMany(ctx, nds)
}

// Get commits and gets a node from the DAGService.
func (bd *BatchDAG) Get(ctx context.Context, c cid.Cid) (Node, error) {
func (bd *BufferedDAG) Get(ctx context.Context, c cid.Cid) (Node, error) {
err := bd.b.Commit()
if err != nil {
return nil, err
Expand All @@ -260,7 +260,7 @@ func (bd *BatchDAG) Get(ctx context.Context, c cid.Cid) (Node, error) {
}

// GetMany commits and gets nodes from the DAGService.
func (bd *BatchDAG) GetMany(ctx context.Context, cs []cid.Cid) <-chan *NodeOption {
func (bd *BufferedDAG) GetMany(ctx context.Context, cs []cid.Cid) <-chan *NodeOption {
err := bd.b.Commit()
if err != nil {
ch := make(chan *NodeOption, 1)
Expand All @@ -275,7 +275,7 @@ func (bd *BatchDAG) GetMany(ctx context.Context, cs []cid.Cid) <-chan *NodeOptio
}

// Remove commits and removes a node from the DAGService.
func (bd *BatchDAG) Remove(ctx context.Context, c cid.Cid) error {
func (bd *BufferedDAG) Remove(ctx context.Context, c cid.Cid) error {
err := bd.b.Commit()
if err != nil {
return err
Expand All @@ -284,7 +284,7 @@ func (bd *BatchDAG) Remove(ctx context.Context, c cid.Cid) error {
}

// RemoveMany commits and removes nodes from the DAGService.
func (bd *BatchDAG) RemoveMany(ctx context.Context, cs []cid.Cid) error {
func (bd *BufferedDAG) RemoveMany(ctx context.Context, cs []cid.Cid) error {
err := bd.b.Commit()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func TestBatch(t *testing.T) {
}
}

func TestBatchDAG(t *testing.T) {
func TestBufferedDAG(t *testing.T) {
ds := newTestDag()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var bdag DAGService = NewBatchDAG(ctx, ds)
var bdag DAGService = NewBufferedDAG(ctx, ds)

for i := 0; i < 1000; i++ {
n := new(EmptyNode)
Expand Down

0 comments on commit e0a8834

Please sign in to comment.