/src/tdengine/include/util/tarray.h
Line | Count | Source |
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 | 44.4k | #define TARRAY_MIN_SIZE 4 |
26 | 67.9k | #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 | 13.9k | #define TARRAY_SIZE(array) ((array)->size) |
37 | 0 | #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 | 50.9k | static FORCE_INLINE void* taosArrayPush(SArray* pArray, const void* pData) { |
87 | 50.9k | return taosArrayAddBatch(pArray, pData, 1); |
88 | 50.9k | } Unexecuted instantiation: sql-fuzzer.c:taosArrayPush Unexecuted instantiation: parser.c:taosArrayPush Unexecuted instantiation: parTokenizer.c:taosArrayPush Unexecuted instantiation: parTranslater.c:taosArrayPush Line | Count | Source | 86 | 33.9k | static FORCE_INLINE void* taosArrayPush(SArray* pArray, const void* pData) { | 87 | 33.9k | return taosArrayAddBatch(pArray, pData, 1); | 88 | 33.9k | } |
Unexecuted instantiation: parAstParser.c:taosArrayPush Unexecuted instantiation: parAuthenticator.c:taosArrayPush Unexecuted instantiation: parCalcConst.c:taosArrayPush Unexecuted instantiation: parInsertSql.c:taosArrayPush Unexecuted instantiation: parInsertUtil.c:taosArrayPush Unexecuted instantiation: taos_lemon_sql.tab.c:taosArrayPush Unexecuted instantiation: parAstCreater.c:taosArrayPush Unexecuted instantiation: parInsertSml.c:taosArrayPush Unexecuted instantiation: planner.c:taosArrayPush Unexecuted instantiation: planLogicCreater.c:taosArrayPush Unexecuted instantiation: planOptimizer.c:taosArrayPush Unexecuted instantiation: planPhysiCreater.c:taosArrayPush Unexecuted instantiation: planScaleOut.c:taosArrayPush Unexecuted instantiation: planSpliter.c:taosArrayPush Unexecuted instantiation: planUtil.c:taosArrayPush Unexecuted instantiation: planValidator.c:taosArrayPush Unexecuted instantiation: catalog.c:taosArrayPush Unexecuted instantiation: ctgAsync.c:taosArrayPush Unexecuted instantiation: ctgCache.c:taosArrayPush Unexecuted instantiation: ctgDbg.c:taosArrayPush Unexecuted instantiation: ctgRemote.c:taosArrayPush Unexecuted instantiation: ctgRent.c:taosArrayPush Unexecuted instantiation: ctgUtil.c:taosArrayPush Unexecuted instantiation: extConnector.c:taosArrayPush Unexecuted instantiation: functionMgt.c:taosArrayPush Unexecuted instantiation: tudf.c:taosArrayPush Unexecuted instantiation: builtins.c:taosArrayPush Unexecuted instantiation: builtinsimpl.c:taosArrayPush Unexecuted instantiation: thistogram.c:taosArrayPush Unexecuted instantiation: tpercentile.c:taosArrayPush Unexecuted instantiation: tavgfunction.c:taosArrayPush Unexecuted instantiation: tminmax.c:taosArrayPush Unexecuted instantiation: tminmaxavx.c:taosArrayPush Unexecuted instantiation: filter.c:taosArrayPush Unexecuted instantiation: scalar.c:taosArrayPush Unexecuted instantiation: sclfunc.c:taosArrayPush Unexecuted instantiation: sclvector.c:taosArrayPush Unexecuted instantiation: nodesCloneFuncs.c:taosArrayPush Unexecuted instantiation: nodesCodeFuncs.c:taosArrayPush Unexecuted instantiation: nodesEqualFuncs.c:taosArrayPush Unexecuted instantiation: nodesMatchFuncs.c:taosArrayPush Unexecuted instantiation: nodesMsgFuncs.c:taosArrayPush Unexecuted instantiation: nodesRemotePlanToSQL.c:taosArrayPush Unexecuted instantiation: nodesToSQLFuncs.c:taosArrayPush Unexecuted instantiation: nodesTraverseFuncs.c:taosArrayPush Unexecuted instantiation: nodesUtilFuncs.c:taosArrayPush Unexecuted instantiation: extTypeMap.c:taosArrayPush Unexecuted instantiation: queryUtil.c:taosArrayPush Unexecuted instantiation: querymsg.c:taosArrayPush Unexecuted instantiation: trans.c:taosArrayPush Unexecuted instantiation: transCli.c:taosArrayPush Unexecuted instantiation: transComm.c:taosArrayPush Unexecuted instantiation: transSasl.c:taosArrayPush Unexecuted instantiation: transSvr.c:taosArrayPush Unexecuted instantiation: transTLS.c:taosArrayPush Unexecuted instantiation: thttp.c:taosArrayPush Unexecuted instantiation: geomFunc.c:taosArrayPush Unexecuted instantiation: geosWrapper.c:taosArrayPush Unexecuted instantiation: tarray.c:taosArrayPush Unexecuted instantiation: tcompare.c:taosArrayPush Unexecuted instantiation: tconfig.c:taosArrayPush Unexecuted instantiation: tconv.c:taosArrayPush Unexecuted instantiation: tdecompressavx.c:taosArrayPush Unexecuted instantiation: tdigest.c:taosArrayPush Unexecuted instantiation: tencode.c:taosArrayPush Unexecuted instantiation: tenv.c:taosArrayPush Unexecuted instantiation: tgeosctx.c:taosArrayPush Line | Count | Source | 86 | 16.9k | static FORCE_INLINE void* taosArrayPush(SArray* pArray, const void* pData) { | 87 | 16.9k | return taosArrayAddBatch(pArray, pData, 1); | 88 | 16.9k | } |
Unexecuted instantiation: thashutil.c:taosArrayPush Unexecuted instantiation: theap.c:taosArrayPush Unexecuted instantiation: tjson.c:taosArrayPush Unexecuted instantiation: tlog.c:taosArrayPush Unexecuted instantiation: tmempool.c:taosArrayPush Unexecuted instantiation: tpagedbuf.c:taosArrayPush Unexecuted instantiation: tqueue.c:taosArrayPush Unexecuted instantiation: tref.c:taosArrayPush Unexecuted instantiation: tsimplehash.c:taosArrayPush Unexecuted instantiation: tutil.c:taosArrayPush Unexecuted instantiation: tuuid.c:taosArrayPush Unexecuted instantiation: tworker.c:taosArrayPush Unexecuted instantiation: mpDirect.c:taosArrayPush Unexecuted instantiation: tcompression.c:taosArrayPush Unexecuted instantiation: tcurl.c:taosArrayPush Unexecuted instantiation: tsched.c:taosArrayPush Unexecuted instantiation: systable.c:taosArrayPush Unexecuted instantiation: tanalytics.c:taosArrayPush Unexecuted instantiation: tcol.c:taosArrayPush Unexecuted instantiation: tdatablock.c:taosArrayPush Unexecuted instantiation: tdataformat.c:taosArrayPush Unexecuted instantiation: tglobal.c:taosArrayPush Unexecuted instantiation: tmisce.c:taosArrayPush Unexecuted instantiation: tname.c:taosArrayPush Unexecuted instantiation: tpriv.c:taosArrayPush Unexecuted instantiation: ttime.c:taosArrayPush Unexecuted instantiation: ttypes.c:taosArrayPush Unexecuted instantiation: tvariant.c:taosArrayPush Unexecuted instantiation: streamMsg.c:taosArrayPush Unexecuted instantiation: streamWindowPlan.c:taosArrayPush Unexecuted instantiation: tmsg.c:taosArrayPush Unexecuted instantiation: xnode.c:taosArrayPush Unexecuted instantiation: tencrypt.c:taosArrayPush Unexecuted instantiation: streamJson.c:taosArrayPush Unexecuted instantiation: osLocale.c:taosArrayPush Unexecuted instantiation: decimal.c:taosArrayPush |
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 data entry of the given index |
174 | | * @param pArray |
175 | | * @param index |
176 | | * @param fp |
177 | | */ |
178 | | void taosArrayRemoveP(SArray* pArray, size_t index, void (*fp)(void*)); |
179 | | |
180 | | /** |
181 | | * remove batch entry from the given index |
182 | | * @param pArray |
183 | | * @param index |
184 | | */ |
185 | | void taosArrayRemoveBatch(SArray* pArray, size_t index, size_t num, FDelete fp); |
186 | | |
187 | | /** |
188 | | * copy the whole array from source to destination |
189 | | * @param pDst |
190 | | * @param pSrc |
191 | | */ |
192 | | SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize); |
193 | | |
194 | | /** |
195 | | * clone a new array |
196 | | * @param pSrc |
197 | | */ |
198 | | SArray* taosArrayDup(const SArray* pSrc, __array_item_dup_fn_t fn); |
199 | | |
200 | | /** |
201 | | * clear the array (remove all element) |
202 | | * @param pArray |
203 | | */ |
204 | | void taosArrayClear(SArray* pArray); |
205 | | |
206 | | /** |
207 | | * clear the array (remove all element) |
208 | | * @param pArray |
209 | | * @param fp |
210 | | */ |
211 | | |
212 | | void taosArrayClearEx(SArray* pArray, void (*fp)(void*)); |
213 | | |
214 | | void taosArrayClearP(SArray* pArray, void (*fp)(void*)); |
215 | | |
216 | | void taosArrayDestroy(SArray* pArray); |
217 | | |
218 | | void taosArrayDestroyP(SArray* pArray, FDelete fp); |
219 | | |
220 | | void taosArrayDestroyEx(SArray* pArray, FDelete fp); |
221 | | |
222 | | void taosArraySwap(SArray* a, SArray* b); |
223 | | |
224 | | /** |
225 | | * sort the array use qsort |
226 | | * @param pArray |
227 | | * @param compar |
228 | | */ |
229 | | void taosArraySort(SArray* pArray, __compar_fn_t comparFn); |
230 | | |
231 | | /** |
232 | | * sort the array use merge sort |
233 | | * @param pArray |
234 | | * @param compar |
235 | | */ |
236 | | int32_t taosArrayMSort(SArray* pArray, __compar_fn_t comparFn); |
237 | | |
238 | | /** |
239 | | * search the array |
240 | | * @param pArray |
241 | | * @param compar |
242 | | * @param key |
243 | | */ |
244 | | void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags); |
245 | | |
246 | | /** |
247 | | * search the array, return index of the element |
248 | | * @param pArray |
249 | | * @param compar |
250 | | * @param key |
251 | | */ |
252 | | int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t comparFn, int32_t flags); |
253 | | |
254 | | /** |
255 | | * sort the pointer data in the array |
256 | | * @param pArray |
257 | | * @param compar |
258 | | * @param param |
259 | | * @return |
260 | | */ |
261 | | |
262 | | int32_t taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param); |
263 | | |
264 | | int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode); |
265 | | void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t dataSz, int8_t sver); |
266 | | |
267 | | #ifdef __cplusplus |
268 | | } |
269 | | #endif |
270 | | |
271 | | #endif /*_TD_UTIL_ARRAY_H_*/ |