MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / resize

Method resize

src/processor/result/factorized_table.cpp:129–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129void FactorizedTable::resize(uint64_t numTuples) {
130 if (numTuples > this->numTuples) {
131 auto numTuplesToAdd = numTuples - this->numTuples;
132 auto numBytesPerTuple = tableSchema.getNumBytesPerTuple();
133 while (flatTupleBlockCollection->needAllocation(numTuplesToAdd * numBytesPerTuple)) {
134 auto newBlock = std::make_unique<DataBlock>(memoryManager, flatTupleBlockSize);
135 flatTupleBlockCollection->append(std::move(newBlock));
136 auto numTuplesToAddInBlock =
137 std::min(static_cast<uint32_t>(numTuplesToAdd), numFlatTuplesPerBlock);
138 auto block = flatTupleBlockCollection->getLastBlock();
139 block->freeSize -= numBytesPerTuple * numTuplesToAddInBlock;
140 block->numTuples += numTuplesToAddInBlock;
141 numTuplesToAdd -= numTuplesToAddInBlock;
142 }
143 DASSERT(numTuplesToAdd < numFlatTuplesPerBlock);
144 auto block = flatTupleBlockCollection->getLastBlock();
145 block->freeSize -= numBytesPerTuple * numTuplesToAdd;
146 block->numTuples += numTuplesToAdd;
147 } else {
148 auto numTuplesRemaining = numTuples;
149 DASSERT(flatTupleBlockCollection->getBlocks().size() == 1);
150 // TODO: It always adds to the end, so this will leave empty blocks in the middle if it's
151 // reused
152 for (auto& block : flatTupleBlockCollection->getBlocks()) {
153 block->numTuples =
154 std::min(static_cast<uint32_t>(numTuplesRemaining), numFlatTuplesPerBlock);
155 block->freeSize =
156 block->getSizedData().size() - block->numTuples * tableSchema.getNumBytesPerTuple();
157 numTuplesRemaining -= block->numTuples;
158 }
159 DASSERT(numTuplesRemaining == 0);
160 }
161 this->numTuples = numTuples;
162}
163uint8_t* FactorizedTable::appendEmptyTuple() {
164 auto numBytesPerTuple = tableSchema.getNumBytesPerTuple();
165 if (flatTupleBlockCollection->needAllocation(numBytesPerTuple)) {

Callers 2

ResultSetMethod · 0.45

Calls 6

needAllocationMethod · 0.80
getLastBlockMethod · 0.80
getSizedDataMethod · 0.80
getNumBytesPerTupleMethod · 0.45
appendMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected