mirror of
https://github.com/arnaucube/arbo.git
synced 2026-01-09 07:21:28 +01:00
Fix VirtualTree.addBatch bucket levels
This commit is contained in:
2
vt.go
2
vt.go
@@ -173,7 +173,7 @@ func (t *vt) addBatch(ks, vs [][]byte) ([]int, error) {
|
|||||||
wg.Add(nCPU)
|
wg.Add(nCPU)
|
||||||
for i := 0; i < nCPU; i++ {
|
for i := 0; i < nCPU; i++ {
|
||||||
go func(cpu int) {
|
go func(cpu int) {
|
||||||
bucketVT := newVT(t.params.maxLevels-l, t.params.hashFunction)
|
bucketVT := newVT(t.params.maxLevels, t.params.hashFunction)
|
||||||
bucketVT.root = nodesAtL[cpu]
|
bucketVT.root = nodesAtL[cpu]
|
||||||
for j := 0; j < len(buckets[cpu]); j++ {
|
for j := 0; j < len(buckets[cpu]); j++ {
|
||||||
if err = bucketVT.add(l, buckets[cpu][j].k, buckets[cpu][j].v); err != nil {
|
if err = bucketVT.add(l, buckets[cpu][j].k, buckets[cpu][j].v); err != nil {
|
||||||
|
|||||||
24
vt_test.go
24
vt_test.go
@@ -143,6 +143,30 @@ func TestVirtualTreeAddBatch(t *testing.T) {
|
|||||||
c.Assert(vTree.root.h, qt.DeepEquals, root)
|
c.Assert(vTree.root.h, qt.DeepEquals, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVirtualTreeAddBatchFullyUsed(t *testing.T) {
|
||||||
|
c := qt.New(t)
|
||||||
|
|
||||||
|
vTree1 := newVT(7, HashFunctionPoseidon) // used for add one by one
|
||||||
|
vTree2 := newVT(7, HashFunctionPoseidon) // used for addBatch
|
||||||
|
|
||||||
|
var keys, values [][]byte
|
||||||
|
for i := 0; i < 128; i++ {
|
||||||
|
k := BigIntToBytes(32, big.NewInt(int64(i)))
|
||||||
|
v := k
|
||||||
|
|
||||||
|
keys = append(keys, k)
|
||||||
|
values = append(values, v)
|
||||||
|
|
||||||
|
// add one by one expecting no error
|
||||||
|
err := vTree1.add(0, k, v)
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
invalids, err := vTree2.addBatch(keys, values)
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
c.Assert(0, qt.Equals, len(invalids))
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetNodesAtLevel(t *testing.T) {
|
func TestGetNodesAtLevel(t *testing.T) {
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user