Added DataTree::numStoredBytes
This commit is contained in:
parent
0f40619a4a
commit
b8cb2ad450
@ -142,7 +142,7 @@ void DataTree::traverseLeaves(DataNode *root, uint32_t leafOffset, uint32_t begi
|
||||
}
|
||||
|
||||
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root);
|
||||
uint32_t leavesPerChild = intPow(_nodeStore->layout().maxChildrenPerInnerNode(), root->depth()-1);
|
||||
uint32_t leavesPerChild = leavesPerFullChild(*inner);
|
||||
uint32_t beginChild = beginIndex/leavesPerChild;
|
||||
uint32_t endChild = ceilDivision(endIndex, leavesPerChild);
|
||||
|
||||
@ -155,6 +155,28 @@ void DataTree::traverseLeaves(DataNode *root, uint32_t leafOffset, uint32_t begi
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t DataTree::leavesPerFullChild(const DataInnerNode &root) const {
|
||||
return intPow(_nodeStore->layout().maxChildrenPerInnerNode(), root.depth()-1);
|
||||
}
|
||||
|
||||
uint64_t DataTree::numStoredBytes() const {
|
||||
return numStoredBytes(*_rootNode);
|
||||
}
|
||||
|
||||
uint64_t DataTree::numStoredBytes(const DataNode &root) const {
|
||||
const DataLeafNode *leaf = dynamic_cast<const DataLeafNode*>(&root);
|
||||
if (leaf != nullptr) {
|
||||
return leaf->numBytes();
|
||||
}
|
||||
|
||||
const DataInnerNode &inner = dynamic_cast<const DataInnerNode&>(root);
|
||||
uint64_t numBytesInLeftChildren = (inner.numChildren()-1) * leavesPerFullChild(inner);
|
||||
auto lastChild = _nodeStore->load(inner.LastChild()->key());
|
||||
uint64_t numBytesInRightChild = numStoredBytes(*lastChild);
|
||||
|
||||
return numBytesInLeftChildren + numBytesInRightChild;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
void flush() const;
|
||||
|
||||
void traverseLeaves(uint32_t beginIndex, uint32_t endIndex, std::function<void (datanodestore::DataLeafNode*, uint32_t)> func);
|
||||
uint64_t numStoredBytes() const;
|
||||
//TODO Test numStoredBytes()
|
||||
|
||||
private:
|
||||
datanodestore::DataNodeStore *_nodeStore;
|
||||
@ -48,6 +50,8 @@ private:
|
||||
void ifRootHasOnlyOneChildReplaceRootWithItsChild();
|
||||
|
||||
void traverseLeaves(datanodestore::DataNode *root, uint32_t leafOffset, uint32_t beginIndex, uint32_t endIndex, std::function<void (datanodestore::DataLeafNode*, uint32_t)> func);
|
||||
uint32_t leavesPerFullChild(const datanodestore::DataInnerNode &root) const;
|
||||
uint64_t numStoredBytes(const datanodestore::DataNode &root) const;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DataTree);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user