MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / leafSplit

Method leafSplit

source/core/StarBTreeDatabase.cpp:714–740  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

712}
713
714auto BTreeDatabase::BTreeImpl::leafSplit(Leaf& leaf) -> Maybe<Leaf> {
715 if (leaf->elements.size() < 2)
716 return {};
717
718 uint32_t size = 6;
719 bool boundaryFound = false;
720 uint32_t boundary = 0;
721 for (uint32_t i = 0; i < leaf->elements.size(); ++i) {
722 size += parent->m_keySize;
723 size += parent->dataSize(leaf->elements[i].data);
724 if (size > parent->m_blockSize - sizeof(BlockIndex) && !boundaryFound) {
725 boundary = i;
726 boundaryFound = true;
727 }
728 }
729 if (boundary == 0)
730 boundary = 1;
731
732 if (size < parent->m_blockSize * 2 - 2 * sizeof(BlockIndex) - 4) {
733 return {};
734 } else {
735 auto right = make_shared<LeafNode>();
736 right->self = InvalidBlockIndex;
737 leaf->split(*right, boundary);
738 return right;
739 }
740}
741
742auto BTreeDatabase::BTreeImpl::storeLeaf(Leaf leaf) -> Pointer {
743 if (leaf->self != InvalidBlockIndex) {

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
dataSizeMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected