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

Method storeIndex

source/core/StarBTreeDatabase.cpp:581–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

579}
580
581auto BTreeDatabase::BTreeImpl::storeIndex(Index index) -> Pointer {
582 if (index->self != InvalidBlockIndex) {
583 if (!parent->m_uncommitted.contains(index->self)) {
584 parent->freeBlock(index->self);
585 parent->m_indexCache.remove(index->self);
586 index->self = InvalidBlockIndex;
587 }
588 }
589
590 if (index->self == InvalidBlockIndex)
591 index->self = parent->reserveBlock();
592
593 DataStreamBuffer buffer(parent->m_blockSize);
594 buffer.writeData(IndexMagic, 2);
595
596 buffer.write<uint8_t>(index->level);
597 buffer.write<uint32_t>(index->pointers.size());
598 buffer.write<BlockIndex>(*index->beginPointer);
599 for (auto i = index->pointers.begin(); i != index->pointers.end(); ++i) {
600 starAssert(i->key.size() == parent->m_keySize);
601 buffer.writeBytes(i->key);
602 buffer.write<BlockIndex>(i->pointer);
603 }
604
605 parent->updateBlock(index->self, buffer.data());
606
607 parent->m_indexCache.set(index->self, index);
608 return index->self;
609}
610
611void BTreeDatabase::BTreeImpl::deleteIndex(Index index) {
612 parent->m_indexCache.remove(index->self);

Callers 2

tryFlattenMethod · 0.45
flattenVisitorMethod · 0.45

Calls 12

freeBlockMethod · 0.80
reserveBlockMethod · 0.80
updateBlockMethod · 0.80
containsMethod · 0.45
removeMethod · 0.45
writeDataMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
writeBytesMethod · 0.45
dataMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected