Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c4aa0be0
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c4aa0be0
编写于
2月 22, 2022
作者:
H
Haojun Liao
提交者:
GitHub
2月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #8760 from haoyifan/hashtable_cleanup
Hashtable cleanup
上级
f882b496
79502cfe
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
461 addition
and
449 deletion
+461
-449
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+79
-75
src/util/inc/hash.h
src/util/inc/hash.h
+89
-70
src/util/inc/hashfunc.h
src/util/inc/hashfunc.h
+2
-0
src/util/src/hash.c
src/util/src/hash.c
+291
-304
未找到文件。
src/query/src/qExecutor.c
浏览文件 @
c4aa0be0
此差异已折叠。
点击以展开。
src/util/inc/hash.h
浏览文件 @
c4aa0be0
...
...
@@ -24,24 +24,18 @@ extern "C" {
#include "hashfunc.h"
#include "tlockfree.h"
#define HASH_MAX_CAPACITY (1024 * 1024 * 16)
#define HASH_DEFAULT_LOAD_FACTOR (0.75)
#define HASH_INDEX(v, c) ((v) & ((c)-1))
typedef
void
(
*
_hash_free_fn_t
)(
void
*
param
);
// TODO: SHashNode is an internal implementation and should not
// be in the public header file.
typedef
struct
SHashNode
{
struct
SHashNode
*
next
;
uint32_t
hashVal
;
// the hash value of key
uint32_t
dataLen
;
// length of data
uint32_t
keyLen
;
// length of the key
int8_t
removed
;
// flag to indicate removed
int32_t
count
;
// reference count
int32_t
refCount
;
// reference count
char
data
[];
}
SHashNode
;
#define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->dataLen)
#define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode))
#define GET_HASH_PNODE(_n) ((SHashNode *)((char*)(_n) - sizeof(SHashNode)))
typedef
enum
SHashLockTypeE
{
...
...
@@ -49,41 +43,24 @@ typedef enum SHashLockTypeE {
HASH_ENTRY_LOCK
=
1
,
}
SHashLockTypeE
;
typedef
struct
SHashEntry
{
int32_t
num
;
// number of elements in current entry
SRWLatch
latch
;
// entry latch
SHashNode
*
next
;
}
SHashEntry
;
typedef
struct
SHashObj
{
SHashEntry
**
hashList
;
size_t
capacity
;
// number of slots
size_t
size
;
// number of elements in hash table
_hash_fn_t
hashFp
;
// hash function
_hash_free_fn_t
freeFp
;
// hash node free callback function
_equal_fn_t
equalFp
;
// equal function
SRWLatch
lock
;
// read-write spin lock
SHashLockTypeE
type
;
// lock type
bool
enableUpdate
;
// enable update
SArray
*
pMemBlock
;
// memory block allocated for SHashEntry
}
SHashObj
;
typedef
struct
SHashObj
SHashObj
;
/**
* init
the
hash table
* init
ialize a
hash table
*
* @param capacity initial capacity of the hash table
* @param fn hash function to generate the hash value
* @param threadsafe thread safe or not
* @return
* @param capacity initial capacity of the hash table
* @param fn hash function
* @param update whether the hash table allows in place update
* @param type whether the hash table has per entry lock
* @return hash table object
*/
SHashObj
*
taosHashInit
(
size_t
capacity
,
_hash_fn_t
fn
,
bool
update
,
SHashLockTypeE
type
);
/**
* set equal func of the hash table
* @param pHashObj
* @param equalFp
* set equal func of the hash table
*
* @param pHashObj
* @param equalFp
* @return
*/
void
taosHashSetEqualFp
(
SHashObj
*
pHashObj
,
_equal_fn_t
fp
);
...
...
@@ -92,6 +69,7 @@ void taosHashSetFreeFp(SHashObj *pHashObj, _hash_free_fn_t fp);
/**
* return the size of hash table
*
* @param pHashObj
* @return
*/
...
...
@@ -99,73 +77,114 @@ int32_t taosHashGetSize(const SHashObj *pHashObj);
/**
* put element into hash table, if the element with the same key exists, update it
* @param pHashObj
* @param key
* @param keyLen
* @param data
* @param size
* @return
*
* @param pHashObj hash table object
* @param key key
* @param keyLen length of key
* @param data data
* @param size size of data
* @return 0 if success, -1 otherwise
*/
int32_t
taosHashPut
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
data
,
size_t
size
);
/**
* return the payload data with the specified key
*
* @param pHashObj
* @param key
* @param keyLen
* @return
* @param pHashObj
hash table object
* @param key
key
* @param keyLen
length of key
* @return
pointer to data
*/
void
*
taosHashGet
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
);
/**
* apply the udf before return the result
* @param pHashObj
* @param key
* @param keyLen
* @param fp
* @param d
* @return
* Get the data associated with "key". Note that caller needs to make sure
* "d" has enough capacity to accomodate the data.
*
* @param pHashObj hash table object
* @param key key
* @param keyLen length of key
* @param fp function to be called on hash node when the data is found
* @param d buffer
* @return pointer to data
*/
void
*
taosHashGetClone
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
(
*
fp
)(
void
*
),
void
*
d
);
/**
* @param pHashObj
* @param key
* @param keyLen
* @param fp
* @param d
* @param sz
* @return
* Get the data associated with "key". Note that caller needs to take ownership
* of the data "d" and make sure it is deallocated.
*
* @param pHashObj hash table object
* @param key key
* @param keyLen length of key
* @param fp function to be called on hash node when the data is found
* @param d buffer
* @param sz size of the data buffer
* @return pointer to data
*/
void
*
taosHashGetCloneExt
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
(
*
fp
)(
void
*
),
void
**
d
,
size_t
*
sz
);
/**
* remove item with the specified key
* @param pHashObj
* @param key
* @param keyLen
*
* @param pHashObj hash table object
* @param key key
* @param keyLen length of key
* @return 0 if success, -1 otherwise
*/
int32_t
taosHashRemove
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
);
/**
* remove item with the specified key
*
* @param pHashObj hash table object
* @param key key
* @param keyLen length of key
* @param data buffer for data
* @param dsize size of data buffer
* @return 0 if success, -1 otherwise
*/
int32_t
taosHashRemoveWithData
(
SHashObj
*
pHashObj
,
const
void
*
key
,
size_t
keyLen
,
void
*
data
,
size_t
dsize
);
int32_t
taosHashCondTraverse
(
SHashObj
*
pHashObj
,
bool
(
*
fp
)(
void
*
,
void
*
),
void
*
param
);
/**
* traverse through all objects in the hash table and apply "fp" on each node.
* If "fp" returns false when applied on top of a node, the node will also be
* removed from table.
*
* @param pHashObj hash table object
* @param fp function pointer applied on each node
* @param param parameter fed into "fp"
*/
void
taosHashCondTraverse
(
SHashObj
*
pHashObj
,
bool
(
*
fp
)(
void
*
,
void
*
),
void
*
param
);
/**
* clear the contents of the hash table
*
* @param pHashObj hash table object
*/
void
taosHashClear
(
SHashObj
*
pHashObj
);
/**
* clean up hash table
* @param handle
*
* @param pHashObj hash table object
*/
void
taosHashCleanup
(
SHashObj
*
pHashObj
);
/**
* return the number of collisions in the hash table
*
* @param pHashObj
* @return
* @param pHashObj
hash table object
* @return
maximum number of collisions
*/
int32_t
taosHashGetMaxOverflowLinkLength
(
const
SHashObj
*
pHashObj
);
int32_t
taosHashGetMaxOverflowLinkLength
(
SHashObj
*
pHashObj
);
/**
* return the consumed memory of the hash table
*
* @param pHashObj hash table object
* @return consumed memory of the hash table
*/
size_t
taosHashGetMemSize
(
const
SHashObj
*
pHashObj
);
void
*
taosHashIterate
(
SHashObj
*
pHashObj
,
void
*
p
);
...
...
src/util/inc/hashfunc.h
浏览文件 @
c4aa0be0
...
...
@@ -22,6 +22,8 @@ typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
typedef
int32_t
(
*
_equal_fn_t
)(
const
void
*
a
,
const
void
*
b
,
size_t
sz
);
typedef
void
(
*
_hash_free_fn_t
)(
void
*
param
);
/**
* murmur hash algorithm
* @key usually string
...
...
src/util/src/hash.c
浏览文件 @
c4aa0be0
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录