Recursion converted into loop

This commit is contained in:
Daniel A. Nagy 2015-02-01 15:59:20 +01:00
parent 32ed5ba45d
commit 4ea99e804f

View file

@ -206,8 +206,7 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data SectionR
var hash Key
dpaLogger.Debugf("depth: %v, max subtree size: %v, data size: %v", depth, treeSize, size)
switch {
case depth == 0:
if depth == 0 {
// leaf nodes -> content chunks
hash = self.Hash(size, data)
dpaLogger.Debugf("content chunk: max subtree size: %v, data size: %v", treeSize, size)
@ -216,13 +215,11 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data SectionR
Data: data,
Size: size,
}
case size < treeSize:
parentWg.Add(1)
// last item on this level (== size % self.Branches ^ (depth + 1) )
self.split(depth-1, treeSize/self.Branches, key, data, chunkC, errc, parentWg)
return
default:
} else {
for size < treeSize {
treeSize /= self.Branches
depth--
}
// intermediate chunk containing child nodes hashes
branches := int64((size-1)/treeSize) + 1
dpaLogger.Debugf("intermediate node: setting branches: %v, depth: %v, max subtree size: %v, data size: %v", branches, depth, treeSize, size)