Skip to content

Commit

Permalink
Add more insert tests
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Díaz <[email protected]>
  • Loading branch information
aalda and gdiazlo committed Feb 25, 2019
1 parent 17cc74d commit e875cb8
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 94 deletions.
26 changes: 13 additions & 13 deletions balloon/hyper2/pruning2/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
// at the end of a batch tree
if iBatch > 0 && pos.Height%4 == 0 {
traverse(pos, leaves, nil, 0, ops)
ops.Push(putInCache(pos, batch))
ops.Push(updateBatchNode(pos, iBatch, batch))
return
}

Expand All @@ -92,7 +92,7 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
batch.ResetElementAt(iBatch)
batch.ResetElementAt(2*iBatch + 1)
batch.ResetElementAt(2*iBatch + 2)
traverse(pos, leaves, batch, iBatch, ops)
traverseThroughCache(pos, leaves, batch, iBatch, ops)
return
}
}
Expand All @@ -102,8 +102,8 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
rightPos := pos.Right()
leftLeaves, rightLeaves := leaves.Split(rightPos.Index)

traverse(pos.Left(), leftLeaves, batch, 2*iBatch+1, ops)
traverse(rightPos, rightLeaves, batch, 2*iBatch+2, ops)
traverseThroughCache(pos.Left(), leftLeaves, batch, 2*iBatch+1, ops)
traverseThroughCache(rightPos, rightLeaves, batch, 2*iBatch+2, ops)

ops.PushAll(innerHash(pos), updateBatchNode(pos, iBatch, batch))
if iBatch == 0 { // it's the root of the batch tree
Expand Down Expand Up @@ -132,8 +132,8 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
// create or update the leaf with a new shortcut
newBatch := NewEmptyBatchNode(len(pos.Index))
ops.PushAll(
shortcutHash(pos, leaves[0].Index, leaves[0].Value),
updateBatchLeaf(pos, 0, newBatch, leaves[0].Index, leaves[0].Value),
leafHash(pos, leaves[0].Value),
updateBatchShortcut(pos, 0, newBatch, leaves[0].Index, leaves[0].Value),
mutateBatch(pos, newBatch),
updateBatchNode(pos, iBatch, batch),
)
Expand All @@ -158,8 +158,8 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
// nil value (no previous node stored) so create a new shortcut batch
newBatch := NewEmptyBatchNode(len(pos.Index))
ops.PushAll(
shortcutHash(pos, leaves[0].Index, leaves[0].Value),
updateBatchLeaf(pos, 0, newBatch, leaves[0].Index, leaves[0].Value),
leafHash(pos, leaves[0].Value),
updateBatchShortcut(pos, 0, newBatch, leaves[0].Index, leaves[0].Value),
mutateBatch(pos, newBatch),
updateBatchNode(pos, iBatch, batch),
)
Expand All @@ -172,8 +172,8 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
// we found a nil in our path -> create a shortcut leaf
if !batch.HasElementAt(iBatch) {
ops.PushAll(
shortcutHash(pos, leaves[0].Index, leaves[0].Value),
updateBatchLeaf(pos, iBatch, batch, leaves[0].Index, leaves[0].Value),
leafHash(pos, leaves[0].Value),
updateBatchShortcut(pos, iBatch, batch, leaves[0].Index, leaves[0].Value),
)
if pos.Height%4 == 0 { // at the root or at a leaf of the subtree
ops.Push(mutateBatch(pos, batch))
Expand All @@ -191,7 +191,7 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
batch.ResetElementAt(iBatch)
batch.ResetElementAt(2*iBatch + 1)
batch.ResetElementAt(2*iBatch + 2)
traverse(pos, leaves, batch, iBatch, ops)
traverseAfterCache(pos, leaves, batch, iBatch, ops)
return
}
}
Expand All @@ -201,8 +201,8 @@ func PruneToInsert(index []byte, value []byte, cacheHeightLimit uint16, batches
rightPos := pos.Right()
leftLeaves, rightLeaves := leaves.Split(rightPos.Index)

traverse(pos.Left(), leftLeaves, batch, 2*iBatch+1, ops)
traverse(rightPos, rightLeaves, batch, 2*iBatch+2, ops)
traverseAfterCache(pos.Left(), leftLeaves, batch, 2*iBatch+1, ops)
traverseAfterCache(rightPos, rightLeaves, batch, 2*iBatch+2, ops)

ops.PushAll(innerHash(pos), updateBatchNode(pos, iBatch, batch))
if iBatch == 0 { // at root node -> mutate batch
Expand Down
Loading

0 comments on commit e875cb8

Please sign in to comment.