| 55 | } |
| 56 | |
| 57 | void DataBlockCollection::merge(DataBlockCollection& other) { |
| 58 | if (blocks.empty()) { |
| 59 | append(std::move(other.blocks)); |
| 60 | return; |
| 61 | } |
| 62 | // Pop up the old last block first, and then push back blocks from other into the vector. |
| 63 | auto oldLastBlock = std::move(blocks.back()); |
| 64 | blocks.pop_back(); |
| 65 | append(std::move(other.blocks)); |
| 66 | // Insert back tuples in the old last block to the new last block. |
| 67 | auto newLastBlock = blocks.back().get(); |
| 68 | auto numTuplesToAppendIntoNewLastBlock = |
| 69 | std::min(numTuplesPerBlock - newLastBlock->numTuples, oldLastBlock->numTuples); |
| 70 | DataBlock::copyTuples(oldLastBlock.get(), 0, newLastBlock, newLastBlock->numTuples, |
| 71 | numTuplesToAppendIntoNewLastBlock, numBytesPerTuple); |
| 72 | // If any tuples left in the old last block, shift them to the beginning, and push the old last |
| 73 | // block back. |
| 74 | auto numTuplesLeftForNewBlock = oldLastBlock->numTuples - numTuplesToAppendIntoNewLastBlock; |
| 75 | if (numTuplesLeftForNewBlock > 0) { |
| 76 | auto tupleIdxInOldLastBlock = numTuplesToAppendIntoNewLastBlock; |
| 77 | oldLastBlock->resetNumTuplesAndFreeSize(); |
| 78 | DataBlock::copyTuples(oldLastBlock.get(), tupleIdxInOldLastBlock, oldLastBlock.get(), 0, |
| 79 | numTuplesLeftForNewBlock, numBytesPerTuple); |
| 80 | blocks.push_back(std::move(oldLastBlock)); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | FactorizedTable::FactorizedTable(MemoryManager* memoryManager, FactorizedTableSchema tableSchema) |
| 85 | : memoryManager{memoryManager}, tableSchema{std::move(tableSchema)}, numTuples{0} { |
no test coverage detected