• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3781

31 Mar 2025 08:30AM UTC coverage: 2.494% (-9.5%) from 11.99%
#3781

push

travis-ci

happyguoxy
test:add case 2

1434 of 89904 branches covered (1.6%)

Branch coverage included in aggregate %.

2176 of 54847 relevant lines covered (3.97%)

1.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/include/util/tarray.h
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#ifndef _TD_UTIL_ARRAY_H_
17
#define _TD_UTIL_ARRAY_H_
18

19
#include "talgo.h"
20

21
#ifdef __cplusplus
22
extern "C" {
23
#endif
24

25
#define TARRAY_MIN_SIZE               4
26
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
27
#define TARRAY_ELEM_IDX(array, ele)   (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
28

29
typedef struct SArray {
30
  size_t   size;
31
  uint32_t capacity;
32
  uint32_t elemSize;
33
  void*    pData;
34
} SArray;
35

36
#define TARRAY_SIZE(array) ((array)->size)
37
#define TARRAY_DATA(array) ((array)->pData)
38

39
/**
40
 *
41
 * @param size
42
 * @param elemSize
43
 * @return
44
 */
45
SArray* taosArrayInit(size_t size, size_t elemSize);
46
SArray* taosArrayInit_s(size_t elemSize, size_t initialSize);
47

48
/**
49
 *
50
 * @param tsize
51
 * @return
52
 */
53
int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize);
54

55
/**
56
 *
57
 * @param pArray
58
 * @param pData
59
 * @param nEles
60
 * @return
61
 */
62
void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles);
63

64
/**
65
 *
66
 * @param pArray
67
 * @param comparFn
68
 * @param fp
69
 */
70
void taosArrayRemoveDuplicate(SArray* pArray, __compar_fn_t comparFn, void (*fp)(void*));
71

72
/**
73
 *  add all element from the source array list into the destination
74
 * @param pArray
75
 * @param pInput
76
 * @return
77
 */
78
void* taosArrayAddAll(SArray* pArray, const SArray* pInput);
79

80
/**
81
 *
82
 * @param pArray
83
 * @param pData
84
 * @return
85
 */
86
static FORCE_INLINE void* taosArrayPush(SArray* pArray, const void* pData) {
87
  return taosArrayAddBatch(pArray, pData, 1);
×
88
}
89

90
/**
91
 * @brief reserve the capacity of the array
92
 *
93
 * @param pArray
94
 * @param num
95
 * @return void* the start position of the reserved memory
96
 */
97
void* taosArrayReserve(SArray* pArray, int32_t num);
98

99
/**
100
 *
101
 * @param pArray
102
 */
103
void* taosArrayPop(SArray* pArray);
104

105
/**
106
 * get the data from array
107
 * @param pArray
108
 * @param index
109
 * @return
110
 */
111
void* taosArrayGet(const SArray* pArray, size_t index);
112

113
/**
114
 * get the pointer data from the array
115
 * @param pArray
116
 * @param index
117
 * @return
118
 */
119
void* taosArrayGetP(const SArray* pArray, size_t index);
120

121
/**
122
 * get the last element in the array list
123
 * @param pArray
124
 * @return
125
 */
126
void* taosArrayGetLast(const SArray* pArray);
127

128
/**
129
 * return the size of array
130
 * @param pArray
131
 * @return
132
 */
133
size_t taosArrayGetSize(const SArray* pArray);
134

135
/**
136
 * insert data into array
137
 * @param pArray
138
 * @param index
139
 * @param pData
140
 */
141
void* taosArrayInsert(SArray* pArray, size_t index, const void* pData);
142

143
/**
144
 * set data in array
145
 * @param pArray
146
 * @param index
147
 * @param pData
148
 */
149
void taosArraySet(SArray* pArray, size_t index, void* pData);
150

151
/**
152
 * remove some data entry from front
153
 * @param pArray
154
 * @param cnt
155
 */
156
void taosArrayPopFrontBatch(SArray* pArray, size_t cnt);
157

158
/**
159
 * remove some data entry from front
160
 * @param pArray
161
 * @param cnt
162
 */
163
void taosArrayPopTailBatch(SArray* pArray, size_t cnt);
164

165
/**
166
 * remove data entry of the given index
167
 * @param pArray
168
 * @param index
169
 */
170
void taosArrayRemove(SArray* pArray, size_t index);
171

172
/**
173
 * remove batch entry from the given index
174
 * @param pArray
175
 * @param index
176
 */
177
void taosArrayRemoveBatch(SArray* pArray, size_t index, size_t num, FDelete fp);
178

179
/**
180
 * copy the whole array from source to destination
181
 * @param pDst
182
 * @param pSrc
183
 */
184
SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize);
185

186
/**
187
 * clone a new array
188
 * @param pSrc
189
 */
190
SArray* taosArrayDup(const SArray* pSrc, __array_item_dup_fn_t fn);
191

192
/**
193
 * clear the array (remove all element)
194
 * @param pArray
195
 */
196
void taosArrayClear(SArray* pArray);
197

198
/**
199
 * clear the array (remove all element)
200
 * @param pArray
201
 * @param fp
202
 */
203

204
void taosArrayClearEx(SArray* pArray, void (*fp)(void*));
205

206
void taosArrayClearP(SArray* pArray, void (*fp)(void*));
207

208
void taosArrayDestroy(SArray* pArray);
209

210
void taosArrayDestroyP(SArray* pArray, FDelete fp);
211

212
void taosArrayDestroyEx(SArray* pArray, FDelete fp);
213

214
void taosArraySwap(SArray* a, SArray* b);
215

216
/**
217
 * sort the array use qsort
218
 * @param pArray
219
 * @param compar
220
 */
221
void taosArraySort(SArray* pArray, __compar_fn_t comparFn);
222

223
/**
224
 * sort the array use merge sort
225
 * @param pArray
226
 * @param compar
227
 */
228
int32_t taosArrayMSort(SArray* pArray, __compar_fn_t comparFn);
229

230
/**
231
 * search the array
232
 * @param pArray
233
 * @param compar
234
 * @param key
235
 */
236
void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
237

238
/**
239
 * search the array, return index of the element
240
 * @param pArray
241
 * @param compar
242
 * @param key
243
 */
244
int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags);
245

246
/**
247
 * sort the pointer data in the array
248
 * @param pArray
249
 * @param compar
250
 * @param param
251
 * @return
252
 */
253

254
int32_t taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param);
255

256
int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode);
257
void*   taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t dataSz, int8_t sver);
258

259
#ifdef __cplusplus
260
}
261
#endif
262

263
#endif /*_TD_UTIL_ARRAY_H_*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc