提交 7976d884 编写于 作者: H Hongze Cheng

add interface

上级 e2e52897
......@@ -104,6 +104,15 @@ static FORCE_INLINE void* taosArrayPush(SArray* pArray, const void* pData) {
return taosArrayAddBatch(pArray, pData, 1);
}
/**
* @brief reserve the capacity of the array
*
* @param pArray
* @param num
* @return void* the start position of the reserved memory
*/
void* taosArrayReserve(SArray* pArray, int32_t num);
/**
*
* @param pArray
......
......@@ -185,6 +185,8 @@ int32_t tMapDataSearch(SMapData *pMapData, void *pSearchItem, int32_t (*tGetItem
int32_t (*tItemCmprFn)(const void *, const void *), void *pItem);
int32_t tPutMapData(uint8_t *p, SMapData *pMapData);
int32_t tGetMapData(uint8_t *p, SMapData *pMapData);
int32_t tMapDataToArray(SMapData *pMapData, int32_t itemSize, int32_t (*tGetItemFn)(uint8_t *, void *),
SArray **ppArray);
// other
int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision);
void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey);
......
......@@ -101,6 +101,30 @@ void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t
tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem);
}
int32_t tMapDataToArray(SMapData *pMapData, int32_t itemSize, int32_t (*tGetItemFn)(uint8_t *, void *),
SArray **ppArray) {
int32_t code = 0;
SArray *pArray = taosArrayInit(pMapData->nItem, itemSize);
if (pArray == NULL) {
code = TSDB_CODE_TDB_OUT_OF_MEMORY;
goto _exit;
}
for (int32_t i = 0; i < pMapData->nItem; i++) {
tMapDataGetItemByIdx(pMapData, i, taosArrayReserve(pArray, 1), tGetItemFn);
}
_exit:
if (code) {
*ppArray = NULL;
if (pArray) taosArrayDestroy(pArray);
} else {
*ppArray = pArray;
}
return code;
}
int32_t tPutMapData(uint8_t *p, SMapData *pMapData) {
int32_t n = 0;
......
......@@ -181,6 +181,17 @@ void* taosArrayAddAll(SArray* pArray, const SArray* pInput) {
}
}
void* taosArrayReserve(SArray* pArray, int32_t num) {
if (taosArrayEnsureCap(pArray, pArray->size + num) != 0) {
return NULL;
}
void* dst = TARRAY_GET_ELEM(pArray, pArray->size);
pArray->size += num;
return dst;
}
void* taosArrayPop(SArray* pArray) {
assert(pArray != NULL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册