| 22 | numBytesToRadixSort{numBytesPerTuple - 8} {} |
| 23 | |
| 24 | void RadixSort::sortSingleKeyBlock(const DataBlock& keyBlock) { |
| 25 | auto numBytesSorted = 0ul; |
| 26 | auto numTuplesInKeyBlock = keyBlock.numTuples; |
| 27 | std::queue<TieRange> ties; |
| 28 | // We need to sort the whole keyBlock for the first radix sort, so just mark all tuples as a |
| 29 | // tie. |
| 30 | ties.push(TieRange{0, numTuplesInKeyBlock - 1}); |
| 31 | for (auto i = 0u; i < strKeyColsInfo.size(); i++) { |
| 32 | const auto numBytesToSort = strKeyColsInfo[i].colOffsetInEncodedKeyBlock - numBytesSorted + |
| 33 | strKeyColsInfo[i].getEncodingSize(); |
| 34 | const auto numOfTies = ties.size(); |
| 35 | for (auto j = 0u; j < numOfTies; j++) { |
| 36 | auto keyBlockTie = ties.front(); |
| 37 | ties.pop(); |
| 38 | radixSort(keyBlock.getData() + keyBlockTie.startingTupleIdx * numBytesPerTuple, |
| 39 | keyBlockTie.getNumTuples(), numBytesSorted, numBytesToSort); |
| 40 | |
| 41 | auto newTiesInKeyBlock = |
| 42 | findTies(keyBlock.getData() + keyBlockTie.startingTupleIdx * numBytesPerTuple + |
| 43 | numBytesSorted, |
| 44 | keyBlockTie.getNumTuples(), numBytesToSort, keyBlockTie.startingTupleIdx); |
| 45 | for (auto& newTieInKeyBlock : newTiesInKeyBlock) { |
| 46 | solveStringTies(newTieInKeyBlock, |
| 47 | keyBlock.getData() + newTieInKeyBlock.startingTupleIdx * numBytesPerTuple, ties, |
| 48 | strKeyColsInfo[i]); |
| 49 | } |
| 50 | } |
| 51 | if (ties.empty()) { |
| 52 | return; |
| 53 | } |
| 54 | numBytesSorted += numBytesToSort; |
| 55 | } |
| 56 | |
| 57 | if (numBytesSorted < numBytesPerTuple) { |
| 58 | while (!ties.empty()) { |
| 59 | auto tie = ties.front(); |
| 60 | ties.pop(); |
| 61 | radixSort(keyBlock.getData() + tie.startingTupleIdx * numBytesPerTuple, |
| 62 | tie.getNumTuples(), numBytesSorted, numBytesToRadixSort - numBytesSorted); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void RadixSort::radixSort(uint8_t* keyBlockPtr, uint32_t numTuplesToSort, uint32_t numBytesSorted, |
| 68 | uint32_t numBytesToSort) { |
no test coverage detected