File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -239,10 +239,10 @@ func (t *ZkTrie) CountLeaves() uint64 {
239
239
if err != nil {
240
240
panic ("CountLeaves cannot get root" )
241
241
}
242
- return t .countLeaves (root )
242
+ return t .countLeaves (root , 0 )
243
243
}
244
244
245
- func (t * ZkTrie ) countLeaves (root * zkt.Hash ) uint64 {
245
+ func (t * ZkTrie ) countLeaves (root * zkt.Hash , depth int ) uint64 {
246
246
if root == nil {
247
247
return 0
248
248
}
@@ -255,7 +255,18 @@ func (t *ZkTrie) countLeaves(root *zkt.Hash) uint64 {
255
255
if rootNode .Type == zktrie .NodeTypeLeaf_New {
256
256
return 1
257
257
} else {
258
- return t .countLeaves (rootNode .ChildL ) + t .countLeaves (rootNode .ChildR )
258
+ count := make (chan uint64 )
259
+ if depth < 5 {
260
+ go func () {
261
+ count <- t .countLeaves (rootNode .ChildL , depth + 1 )
262
+ }()
263
+ go func () {
264
+ count <- t .countLeaves (rootNode .ChildR , depth + 1 )
265
+ }()
266
+ return <- count + <- count
267
+ } else {
268
+ return t .countLeaves (rootNode .ChildL , depth + 1 ) + t .countLeaves (rootNode .ChildR , depth + 1 )
269
+ }
259
270
}
260
271
}
261
272
You can’t perform that action at this time.
0 commit comments