add interface
This commit is contained in:
parent
e2e52897a2
commit
7976d88402
|
@ -104,6 +104,15 @@ static FORCE_INLINE void* taosArrayPush(SArray* pArray, const void* pData) {
|
||||||
return taosArrayAddBatch(pArray, pData, 1);
|
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
|
* @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 (*tItemCmprFn)(const void *, const void *), void *pItem);
|
||||||
int32_t tPutMapData(uint8_t *p, SMapData *pMapData);
|
int32_t tPutMapData(uint8_t *p, SMapData *pMapData);
|
||||||
int32_t tGetMapData(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
|
// other
|
||||||
int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision);
|
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);
|
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);
|
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 tPutMapData(uint8_t *p, SMapData *pMapData) {
|
||||||
int32_t n = 0;
|
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) {
|
void* taosArrayPop(SArray* pArray) {
|
||||||
assert(pArray != NULL);
|
assert(pArray != NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue