fix treeSize secSize in split

This commit is contained in:
zelig 2015-01-13 00:32:43 +00:00
parent e8ec302b7a
commit bee2d91955

View file

@ -216,27 +216,29 @@ func (self *TreeChunker) split(depth int, treeSize int64, key Key, data SectionR
Data: data, Data: data,
Size: size, Size: size,
} }
case size < treeSize*self.Branches: case size < treeSize:
// last item on this level (== size % self.Branches ^ (depth + 1) ) // last item on this level (== size % self.Branches ^ (depth + 1) )
self.split(depth-1, treeSize/self.Branches, key, data, chunkC, errc, parentWg) self.split(depth-1, treeSize/self.Branches, key, data, chunkC, errc, parentWg)
return return
default: default:
// intermediate chunk containing child nodes hashes // intermediate chunk containing child nodes hashes
branches := int64(size/treeSize) + 1 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) dpaLogger.Debugf("intermediate node: setting branches: %v, depth: %v, max subtree size: %v, data size: %v", branches, depth, treeSize, size)
var chunk []byte = make([]byte, branches*self.hashSize) var chunk []byte = make([]byte, branches*self.hashSize)
var pos, i int64 var pos, i int64
childrenWg := &sync.WaitGroup{} childrenWg := &sync.WaitGroup{}
var secSize int64
for i < branches { for i < branches {
// the last item can have shorter data // the last item can have shorter data
if size-pos < treeSize*self.Branches { if size-pos < treeSize {
treeSize = size - pos secSize = size - pos
} else {
secSize = treeSize
} }
// take the section of the data corresponding encoded in the subTree // take the section of the data corresponding encoded in the subTree
subTreeData := NewChunkReader(data, pos, treeSize) subTreeData := NewChunkReader(data, pos, secSize)
// the hash of that data // the hash of that data
subTreeKey := chunk[i*self.hashSize : (i+1)*self.hashSize] subTreeKey := chunk[i*self.hashSize : (i+1)*self.hashSize]