Coverage Report

Created: 2026-10-22 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tdengine/include/util/tsimplehash.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * SPDX-License-Identifier: AGPL-3.0-or-later
5
 *
6
 * This program is free software: you can use, redistribute, and/or modify
7
 * it under the terms of the GNU Affero General Public License, version 3
8
 * or later ("AGPL"), as published by the Free Software Foundation.
9
 *
10
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
#ifndef TDENGINE_TSIMPLEHASH_H
19
#define TDENGINE_TSIMPLEHASH_H
20
21
#include "tarray.h"
22
#include "thash.h"
23
24
#ifdef __cplusplus
25
extern "C" {
26
#endif
27
28
/**
29
 * @brief single thread hash
30
 *
31
 */
32
typedef struct SSHashObj SSHashObj;
33
34
/**
35
 * init the hash table
36
 *
37
 * @param capacity    initial capacity of the hash table
38
 * @param fn          hash function to generate the hash value
39
 * @return
40
 */
41
SSHashObj *tSimpleHashInit(size_t capacity, _hash_fn_t fn);
42
43
/**
44
 * return the size of hash table
45
 * @param pHashObj
46
 * @return
47
 */
48
int32_t tSimpleHashGetSize(const SSHashObj *pHashObj);
49
50
/**
51
 * set the free function pointer
52
 * @param pHashObj
53
 * @param freeFp
54
 */
55
void tSimpleHashSetFreeFp(SSHashObj* pHashObj, _hash_free_fn_t freeFp);
56
57
int32_t tSimpleHashPrint(const SSHashObj *pHashObj);
58
59
/**
60
 * @brief put element into hash table, if the element with the same key exists, update it
61
 *
62
 * @param pHashObj
63
 * @param key
64
 * @param keyLen
65
 * @param data
66
 * @param dataLen
67
 * @return int32_t
68
 */
69
int32_t tSimpleHashPut(SSHashObj *pHashObj, const void *key, size_t keyLen, const void *data, size_t dataLen);
70
71
/**
72
 * return the payload data with the specified key
73
 *
74
 * @param pHashObj
75
 * @param key
76
 * @param keyLen
77
 * @return
78
 */
79
void *tSimpleHashGet(SSHashObj *pHashObj, const void *key, size_t keyLen);
80
81
/**
82
 * remove item with the specified key
83
 * @param pHashObj
84
 * @param key
85
 * @param keyLen
86
 */
87
int32_t tSimpleHashRemove(SSHashObj *pHashObj, const void *key, size_t keyLen);
88
89
/**
90
 * remove item with the specified key during hash iterate
91
 *
92
 * @param pHashObj
93
 * @param key
94
 * @param keyLen
95
 * @param pIter
96
 * @param iter
97
 * @return int32_t
98
 */
99
int32_t tSimpleHashIterateRemove(SSHashObj *pHashObj, const void *key, size_t keyLen, void **pIter, int32_t *iter);
100
101
/**
102
 * Clear the hash table.
103
 * @param pHashObj
104
 */
105
void tSimpleHashClear(SSHashObj *pHashObj);
106
107
/**
108
 * Clean up hash table and release all allocated resources.
109
 * @param handle
110
 */
111
void tSimpleHashCleanup(SSHashObj *pHashObj);
112
113
/**
114
 * Get the hash table size
115
 * @param pHashObj
116
 * @return
117
 */
118
size_t tSimpleHashGetMemSize(const SSHashObj *pHashObj);
119
120
#pragma pack(push, 4)
121
typedef struct SHNode {
122
  struct SHNode *next;
123
  uint32_t       keyLen : 20;
124
  uint32_t       dataLen : 12;
125
  uint32_t       hashVal;
126
  char           data[];
127
} SHNode;
128
#pragma pack(pop)
129
130
/**
131
 * Get the corresponding key information for a given data in hash table
132
 * @param data
133
 * @param keyLen
134
 * @return
135
 */
136
0
static FORCE_INLINE void *tSimpleHashGetKey(void *data, size_t *keyLen) {
137
0
  SHNode *node = (SHNode *)((char *)data - offsetof(SHNode, data));
138
0
  if (keyLen) *keyLen = node->keyLen;
139
140
0
  return POINTER_SHIFT(data, node->dataLen);
141
0
}
Unexecuted instantiation: sql-fuzzer.c:tSimpleHashGetKey
Unexecuted instantiation: parser.c:tSimpleHashGetKey
Unexecuted instantiation: parTranslater.c:tSimpleHashGetKey
Unexecuted instantiation: parUtil.c:tSimpleHashGetKey
Unexecuted instantiation: parAstParser.c:tSimpleHashGetKey
Unexecuted instantiation: parAuthenticator.c:tSimpleHashGetKey
Unexecuted instantiation: parCalcConst.c:tSimpleHashGetKey
Unexecuted instantiation: parInsertSql.c:tSimpleHashGetKey
Unexecuted instantiation: parInsertUtil.c:tSimpleHashGetKey
Unexecuted instantiation: taos_lemon_sql.tab.c:tSimpleHashGetKey
Unexecuted instantiation: parAstCreater.c:tSimpleHashGetKey
Unexecuted instantiation: parInsertSml.c:tSimpleHashGetKey
Unexecuted instantiation: planner.c:tSimpleHashGetKey
Unexecuted instantiation: planLogicCreater.c:tSimpleHashGetKey
Unexecuted instantiation: planOptimizer.c:tSimpleHashGetKey
Unexecuted instantiation: planPhysiCreater.c:tSimpleHashGetKey
Unexecuted instantiation: planScaleOut.c:tSimpleHashGetKey
Unexecuted instantiation: planSpliter.c:tSimpleHashGetKey
Unexecuted instantiation: planUtil.c:tSimpleHashGetKey
Unexecuted instantiation: planValidator.c:tSimpleHashGetKey
Unexecuted instantiation: catalog.c:tSimpleHashGetKey
Unexecuted instantiation: ctgAsync.c:tSimpleHashGetKey
Unexecuted instantiation: ctgCache.c:tSimpleHashGetKey
Unexecuted instantiation: ctgDbg.c:tSimpleHashGetKey
Unexecuted instantiation: ctgRemote.c:tSimpleHashGetKey
Unexecuted instantiation: ctgRent.c:tSimpleHashGetKey
Unexecuted instantiation: ctgUtil.c:tSimpleHashGetKey
Unexecuted instantiation: extConnector.c:tSimpleHashGetKey
Unexecuted instantiation: extDialect.c:tSimpleHashGetKey
Unexecuted instantiation: extDialectDefaults.c:tSimpleHashGetKey
Unexecuted instantiation: functionMgt.c:tSimpleHashGetKey
Unexecuted instantiation: tudf.c:tSimpleHashGetKey
Unexecuted instantiation: builtins.c:tSimpleHashGetKey
Unexecuted instantiation: builtinsimpl.c:tSimpleHashGetKey
Unexecuted instantiation: spillDistinctSet.c:tSimpleHashGetKey
Unexecuted instantiation: thistogram.c:tSimpleHashGetKey
Unexecuted instantiation: tpercentile.c:tSimpleHashGetKey
Unexecuted instantiation: tavgfunction.c:tSimpleHashGetKey
Unexecuted instantiation: tminmax.c:tSimpleHashGetKey
Unexecuted instantiation: tminmaxavx.c:tSimpleHashGetKey
Unexecuted instantiation: filter.c:tSimpleHashGetKey
Unexecuted instantiation: scalar.c:tSimpleHashGetKey
Unexecuted instantiation: sclfunc.c:tSimpleHashGetKey
Unexecuted instantiation: sclvector.c:tSimpleHashGetKey
Unexecuted instantiation: nodesCloneFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: nodesCodeFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: nodesEqualFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: nodesMatchFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: nodesMsgFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: nodesRemotePlanToSQL.c:tSimpleHashGetKey
Unexecuted instantiation: nodesToSQLFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: nodesTraverseFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: nodesUtilFuncs.c:tSimpleHashGetKey
Unexecuted instantiation: extTypeMap.c:tSimpleHashGetKey
Unexecuted instantiation: queryUtil.c:tSimpleHashGetKey
Unexecuted instantiation: querymsg.c:tSimpleHashGetKey
Unexecuted instantiation: trans.c:tSimpleHashGetKey
Unexecuted instantiation: transCli.c:tSimpleHashGetKey
Unexecuted instantiation: transComm.c:tSimpleHashGetKey
Unexecuted instantiation: transSasl.c:tSimpleHashGetKey
Unexecuted instantiation: transSvr.c:tSimpleHashGetKey
Unexecuted instantiation: transTLS.c:tSimpleHashGetKey
Unexecuted instantiation: thttp.c:tSimpleHashGetKey
Unexecuted instantiation: geomFunc.c:tSimpleHashGetKey
Unexecuted instantiation: tconfig.c:tSimpleHashGetKey
Unexecuted instantiation: tdigest.c:tSimpleHashGetKey
Unexecuted instantiation: tlog.c:tSimpleHashGetKey
Unexecuted instantiation: tmempool.c:tSimpleHashGetKey
Unexecuted instantiation: tpagedbuf.c:tSimpleHashGetKey
Unexecuted instantiation: tsimplehash.c:tSimpleHashGetKey
Unexecuted instantiation: mpDirect.c:tSimpleHashGetKey
Unexecuted instantiation: extCapability.c:tSimpleHashGetKey
Unexecuted instantiation: systable.c:tSimpleHashGetKey
Unexecuted instantiation: tanalytics.c:tSimpleHashGetKey
Unexecuted instantiation: tdatablock.c:tSimpleHashGetKey
Unexecuted instantiation: tdataformat.c:tSimpleHashGetKey
Unexecuted instantiation: tglobal.c:tSimpleHashGetKey
Unexecuted instantiation: tmisce.c:tSimpleHashGetKey
Unexecuted instantiation: tname.c:tSimpleHashGetKey
Unexecuted instantiation: tpriv.c:tSimpleHashGetKey
Unexecuted instantiation: ttime.c:tSimpleHashGetKey
Unexecuted instantiation: tvariant.c:tSimpleHashGetKey
Unexecuted instantiation: streamMsg.c:tSimpleHashGetKey
Unexecuted instantiation: streamWindowPlan.c:tSimpleHashGetKey
Unexecuted instantiation: tmsg.c:tSimpleHashGetKey
Unexecuted instantiation: xnode.c:tSimpleHashGetKey
Unexecuted instantiation: tencrypt.c:tSimpleHashGetKey
Unexecuted instantiation: streamJson.c:tSimpleHashGetKey
Unexecuted instantiation: decimal.c:tSimpleHashGetKey
Unexecuted instantiation: crypt.c:tSimpleHashGetKey
142
143
/**
144
 * Create the hash table iterator
145
 * @param pHashObj
146
 * @param data
147
 * @param iter
148
 * @return void*
149
 */
150
void *tSimpleHashIterate(const SSHashObj *pHashObj, void *data, int32_t *iter);
151
152
#ifdef __cplusplus
153
}
154
#endif
155
#endif  // TDENGINE_TSIMPLEHASH_H