提交 17951639 编写于 作者: H Haojun Liao

refactor: remove redundant codes.

上级 5dcfaf3b
......@@ -41,286 +41,6 @@ static bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCe
static void tdSCellValPrint(SCellVal *pVal, int8_t colType);
// implementation
/**
* @brief Compress bitmap bytes comprised of 2-bits to counterpart of 1-bit.
* e.g.
* TD_VTYPE_NORM 0x00U(00000000) to 00000000 Normal
* TD_VTYPE_NULL 0x01U(00000001) to 00000001 Null
* TD_VTYPE_NONE 0x02U(00000010) to 00000001 Null
*
* 00000000 0x00 0x00
* 01000000 0x40 0x08
* 10000000 0x80 0x08
* ...
* @param byte
* @return uint8_t
*/
static uint8_t tdGetMergedBitmapByte(uint8_t byte) {
switch (byte) {
case 0x00:
return 0x00;
case 0x40:
return 0x08;
case 0x80:
return 0x08;
case 0x10:
return 0x04;
case 0x50:
return 0x0c;
case 0x90:
return 0x0c;
case 0x20:
return 0x04;
case 0x60:
return 0x0c;
case 0xa0:
return 0x0c;
case 0x04:
return 0x02;
case 0x44:
return 0x0a;
case 0x84:
return 0x0a;
case 0x14:
return 0x06;
case 0x54:
return 0x0e;
case 0x94:
return 0x0e;
case 0x24:
return 0x06;
case 0x64:
return 0x0e;
case 0xa4:
return 0x0e;
case 0x08:
return 0x02;
case 0x48:
return 0x0a;
case 0x88:
return 0x0a;
case 0x18:
return 0x06;
case 0x58:
return 0x0e;
case 0x98:
return 0x0e;
case 0x28:
return 0x06;
case 0x68:
return 0x0e;
case 0xa8:
return 0x0e;
case 0x01:
return 0x01;
case 0x41:
return 0x09;
case 0x81:
return 0x09;
case 0x11:
return 0x05;
case 0x51:
return 0x0d;
case 0x91:
return 0x0d;
case 0x21:
return 0x05;
case 0x61:
return 0x0d;
case 0xa1:
return 0x0d;
case 0x05:
return 0x03;
case 0x45:
return 0x0b;
case 0x85:
return 0x0b;
case 0x15:
return 0x07;
case 0x55:
return 0x0f;
case 0x95:
return 0x0f;
case 0x25:
return 0x07;
case 0x65:
return 0x0f;
case 0xa5:
return 0x0f;
case 0x09:
return 0x03;
case 0x49:
return 0x0b;
case 0x89:
return 0x0b;
case 0x19:
return 0x07;
case 0x59:
return 0x0f;
case 0x99:
return 0x0f;
case 0x29:
return 0x07;
case 0x69:
return 0x0f;
case 0xa9:
return 0x0f;
case 0x02:
return 0x01;
case 0x42:
return 0x09;
case 0x82:
return 0x09;
case 0x12:
return 0x05;
case 0x52:
return 0x0d;
case 0x92:
return 0x0d;
case 0x22:
return 0x05;
case 0x62:
return 0x0d;
case 0xa2:
return 0x0d;
case 0x06:
return 0x03;
case 0x46:
return 0x0b;
case 0x86:
return 0x0b;
case 0x16:
return 0x07;
case 0x56:
return 0x0f;
case 0x96:
return 0x0f;
case 0x26:
return 0x07;
case 0x66:
return 0x0f;
case 0xa6:
return 0x0f;
case 0x0a:
return 0x03;
case 0x4a:
return 0x0b;
case 0x8a:
return 0x0b;
case 0x1a:
return 0x07;
case 0x5a:
return 0x0f;
case 0x9a:
return 0x0f;
case 0x2a:
return 0x07;
case 0x6a:
return 0x0f;
case 0xaa:
return 0x0f;
default:
// make sure the bitmap area is set to 0 firstly
ASSERT(0);
return 0x0f; // return NULL bitmap for exception
}
}
/**
* @brief Merge bitmap from 2 bits to 1 bit, and the memory buffer should be guaranteed by the invoker.
*
* @param srcBitmap
* @param nBits
* @param dstBitmap
*/
void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap) {
int32_t i = 0, j = 0;
int32_t nBytes = TD_BITMAP_BYTES(nBits);
int32_t nRoundBytes = nBits / 4;
int32_t nRemainderBits = nBits - nRoundBytes * 4;
switch (nRemainderBits) {
case 0:
// NOTHING TODO
break;
case 1: {
void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes);
*(uint8_t *)lastByte &= 0xC0;
} break;
case 2: {
void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes);
*(uint8_t *)lastByte &= 0xF0;
} break;
case 3: {
void *lastByte = POINTER_SHIFT(srcBitmap, nRoundBytes);
*(uint8_t *)lastByte &= 0xFC;
} break;
default:
ASSERT(0);
}
if (nBytes > 0) {
dstBitmap[j] = (tdGetMergedBitmapByte(srcBitmap[i]) << 4);
}
while ((++i) < nBytes) {
if ((i & 1) == 0) {
dstBitmap[j] = (tdGetMergedBitmapByte(srcBitmap[i]) << 4);
} else {
dstBitmap[j] |= tdGetMergedBitmapByte(srcBitmap[i]);
++j;
}
}
}
/**
* @brief Set bitmap area by byte preferentially and then by bit.
*
* @param pBitmap
* @param nEle
* @param valType
* @param bitmapMode 0 for 2 bits, 1 for 1 bit
* @return int32_t
*/
int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType, int8_t bitmapMode) {
TASSERT(valType < TD_VTYPE_MAX);
int32_t nBytes = (bitmapMode == 0 ? nEle / TD_VTYPE_PARTS : nEle / TD_VTYPE_PARTS_I);
uint8_t vTypeByte = tdVTypeByte[bitmapMode][valType];
for (int i = 0; i < nBytes; ++i) {
*(uint8_t *)pBitmap = vTypeByte;
pBitmap = POINTER_SHIFT(pBitmap, 1);
}
int32_t nLeft = nEle - nBytes * (bitmapMode == 0 ? TD_VTYPE_BITS : TD_VTYPE_BITS_I);
for (int j = 0; j < nLeft; ++j) {
tdSetBitmapValType(pBitmap, j, valType, bitmapMode);
}
return TSDB_CODE_SUCCESS;
}
bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode) {
int32_t nBytes = (bitmapMode == 0 ? numOfBits / TD_VTYPE_PARTS : numOfBits / TD_VTYPE_PARTS_I);
uint8_t vTypeByte = tdVTypeByte[bitmapMode][TD_VTYPE_NORM];
uint8_t *qBitmap = (uint8_t *)pBitmap;
for (int i = 0; i < nBytes; ++i) {
if (*qBitmap != vTypeByte) {
return false;
}
qBitmap = (uint8_t *)POINTER_SHIFT(pBitmap, i);
}
int32_t nLeft = numOfBits - nBytes * (bitmapMode == 0 ? TD_VTYPE_BITS : TD_VTYPE_BITS_I);
for (int j = 0; j < nLeft; ++j) {
uint8_t vType;
tdGetBitmapValType(qBitmap, j, &vType, bitmapMode);
if (vType != TD_VTYPE_NORM) {
return false;
}
}
return true;
}
STSRow *tdRowDup(STSRow *row) {
STSRow *trow = taosMemoryMalloc(TD_ROW_LEN(row));
if (trow == NULL) return NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册