Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cb71affe
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1191
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cb71affe
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hash
上级
e7852552
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
76 addition
and
100 deletion
+76
-100
include/util/theap.h
include/util/theap.h
+12
-12
include/util/tidpool.h
include/util/tidpool.h
+11
-18
source/util/src/thashutil.c
source/util/src/thashutil.c
+5
-6
source/util/src/theap.c
source/util/src/theap.c
+28
-45
source/util/src/tidpool.c
source/util/src/tidpool.c
+20
-19
未找到文件。
include/util/theap.h
浏览文件 @
cb71affe
...
...
@@ -12,19 +12,20 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_HEAP_H
#define TDENGINE_HEAP_H
#ifndef _TD_UTIL_HEAP_H_
#define _TD_UTIL_HEAP_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#include "os.h"
struct
HeapNode
;
/* Return non-zero if a < b. */
typedef
int
(
*
HeapCompareFn
)(
const
struct
HeapNode
*
a
,
const
struct
HeapNode
*
b
);
typedef
int
32_t
(
*
HeapCompareFn
)(
const
struct
HeapNode
*
a
,
const
struct
HeapNode
*
b
);
typedef
struct
HeapNode
{
struct
HeapNode
*
left
;
...
...
@@ -38,15 +39,14 @@ typedef struct HeapNode {
*
*/
typedef
struct
{
HeapNode
*
min
;
size_t
nelts
;
HeapCompareFn
compFn
;
HeapNode
*
min
;
size_t
nelts
;
HeapCompareFn
compFn
;
}
Heap
;
Heap
*
heapCreate
(
HeapCompareFn
fn
);
void
heapDestroy
(
Heap
*
heap
);
void
heapDestroy
(
Heap
*
heap
);
HeapNode
*
heapMin
(
const
Heap
*
heap
);
...
...
@@ -56,10 +56,10 @@ void heapRemove(Heap* heap, struct HeapNode* node);
void
heapDequeue
(
Heap
*
heap
);
size_t
heapSize
(
Heap
*
heap
);
size_t
heapSize
(
Heap
*
heap
);
#ifdef __cplusplus
}
#endif
#endif
// TDENGINE_HASH_H
#endif
/*_TD_UTIL_HEAP_H_*/
include/util/tidpool.h
浏览文件 @
cb71affe
...
...
@@ -13,31 +13,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_IDPOOL_H
#define _TD_UTIL_IDPOOL_H
#ifndef _TD_UTIL_IDPOOL_H
_
#define _TD_UTIL_IDPOOL_H
_
#ifdef __cplusplus
extern
"C"
{
#endif
void
*
taosInitIdPool
(
int
maxId
);
int
taosUpdateIdPool
(
void
*
handle
,
int
maxId
);
int
taosIdPoolMaxSize
(
void
*
handle
);
int
taosAllocateId
(
void
*
handle
);
void
taosFreeId
(
void
*
handle
,
int
id
);
void
taosIdPoolCleanUp
(
void
*
handle
);
int
taosIdPoolNumOfUsed
(
void
*
handle
);
bool
taosIdPoolMarkStatus
(
void
*
handle
,
int
id
);
void
*
taosInitIdPool
(
int32_t
maxId
);
int32_t
taosUpdateIdPool
(
void
*
handle
,
int32_t
maxId
);
int32_t
taosIdPoolMaxSize
(
void
*
handle
);
int32_t
taosAllocateId
(
void
*
handle
);
void
taosFreeId
(
void
*
handle
,
int32_t
id
);
void
taosIdPoolCleanUp
(
void
*
handle
);
int32_t
taosIdPoolNumOfUsed
(
void
*
handle
);
bool
taosIdPoolMarkStatus
(
void
*
handle
,
int32_t
id
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_UTIL_IDPOOL_H*/
#endif
/*_TD_UTIL_IDPOOL_H
_
*/
source/util/src/thashutil.c
浏览文件 @
cb71affe
...
...
@@ -13,10 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#
include "os.h"
#
define _DEFAULT_SOURCE
#include "thash.h"
#include "tcompare.h"
#include "taos.h"
#include "types.h"
#define ROTL32(x, r) ((x) << (r) | (x) >> (32u - (r)))
...
...
@@ -34,7 +33,7 @@
uint32_t
MurmurHash3_32
(
const
char
*
key
,
uint32_t
len
)
{
const
uint8_t
*
data
=
(
const
uint8_t
*
)
key
;
const
int
nblocks
=
len
>>
2u
;
const
int
32_t
nblocks
=
len
>>
2u
;
uint32_t
h1
=
0x12345678
;
...
...
@@ -43,7 +42,7 @@ uint32_t MurmurHash3_32(const char *key, uint32_t len) {
const
uint32_t
*
blocks
=
(
const
uint32_t
*
)(
data
+
nblocks
*
4
);
for
(
int
i
=
-
nblocks
;
i
;
i
++
)
{
for
(
int
32_t
i
=
-
nblocks
;
i
;
i
++
)
{
uint32_t
k1
=
blocks
[
i
];
k1
*=
c1
;
...
...
@@ -92,7 +91,7 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) {
return
0
;
}
if
(
fabs
(
f
)
<
FLT_MAX
/
BASE
-
DLT
)
{
int
t
=
(
in
t
)(
round
(
BASE
*
(
f
+
DLT
)));
int
32_t
t
=
(
int32_
t
)(
round
(
BASE
*
(
f
+
DLT
)));
return
(
uint32_t
)
t
;
}
else
{
return
0x7fc00000
;
...
...
@@ -108,7 +107,7 @@ uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) {
return
0
;
}
if
(
fabs
(
f
)
<
DBL_MAX
/
BASE
-
DLT
)
{
int
t
=
(
in
t
)(
round
(
BASE
*
(
f
+
DLT
)));
int
32_t
t
=
(
int32_
t
)(
round
(
BASE
*
(
f
+
DLT
)));
return
(
uint32_t
)
t
;
}
else
{
return
0x7fc00000
;
...
...
source/util/src/theap.c
浏览文件 @
cb71affe
...
...
@@ -13,15 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "theap.h"
size_t
heapSize
(
Heap
*
heap
)
{
return
heap
->
nelts
;
}
size_t
heapSize
(
Heap
*
heap
)
{
return
heap
->
nelts
;
}
Heap
*
heapCreate
(
HeapCompareFn
fn
)
{
Heap
*
heap
=
calloc
(
1
,
sizeof
(
Heap
));
if
(
heap
==
NULL
)
{
return
NULL
;
}
Heap
*
heap
=
calloc
(
1
,
sizeof
(
Heap
));
if
(
heap
==
NULL
)
{
return
NULL
;
}
heap
->
min
=
NULL
;
heap
->
nelts
=
0
;
...
...
@@ -29,18 +30,14 @@ Heap* heapCreate(HeapCompareFn fn) {
return
heap
;
}
void
heapDestroy
(
Heap
*
heap
)
{
free
(
heap
);
}
void
heapDestroy
(
Heap
*
heap
)
{
free
(
heap
);
}
HeapNode
*
heapMin
(
const
Heap
*
heap
)
{
return
heap
->
min
;
}
HeapNode
*
heapMin
(
const
Heap
*
heap
)
{
return
heap
->
min
;
}
/* Swap parent with child. Child moves closer to the root, parent moves away. */
static
void
heapNodeSwap
(
Heap
*
heap
,
HeapNode
*
parent
,
HeapNode
*
child
)
{
HeapNode
*
sibling
;
HeapNode
t
;
HeapNode
t
;
t
=
*
parent
;
*
parent
=
*
child
;
...
...
@@ -54,13 +51,10 @@ static void heapNodeSwap(Heap* heap, HeapNode* parent, HeapNode* child) {
child
->
right
=
parent
;
sibling
=
child
->
left
;
}
if
(
sibling
!=
NULL
)
sibling
->
parent
=
child
;
if
(
sibling
!=
NULL
)
sibling
->
parent
=
child
;
if
(
parent
->
left
!=
NULL
)
parent
->
left
->
parent
=
parent
;
if
(
parent
->
right
!=
NULL
)
parent
->
right
->
parent
=
parent
;
if
(
parent
->
left
!=
NULL
)
parent
->
left
->
parent
=
parent
;
if
(
parent
->
right
!=
NULL
)
parent
->
right
->
parent
=
parent
;
if
(
child
->
parent
==
NULL
)
heap
->
min
=
child
;
...
...
@@ -73,9 +67,9 @@ static void heapNodeSwap(Heap* heap, HeapNode* parent, HeapNode* child) {
void
heapInsert
(
Heap
*
heap
,
HeapNode
*
newnode
)
{
HeapNode
**
parent
;
HeapNode
**
child
;
u
nsigned
int
path
;
u
nsigned
int
n
;
u
nsigned
int
k
;
u
int32_t
path
;
u
int32_t
n
;
u
int32_t
k
;
newnode
->
left
=
NULL
;
newnode
->
right
=
NULL
;
...
...
@@ -85,8 +79,7 @@ void heapInsert(Heap* heap, HeapNode* newnode) {
* heap so we always insert at the left-most free node of the bottom row.
*/
path
=
0
;
for
(
k
=
0
,
n
=
1
+
heap
->
nelts
;
n
>=
2
;
k
+=
1
,
n
/=
2
)
path
=
(
path
<<
1
)
|
(
n
&
1
);
for
(
k
=
0
,
n
=
1
+
heap
->
nelts
;
n
>=
2
;
k
+=
1
,
n
/=
2
)
path
=
(
path
<<
1
)
|
(
n
&
1
);
/* Now traverse the heap using the path we calculated in the previous step. */
parent
=
child
=
&
heap
->
min
;
...
...
@@ -113,22 +106,20 @@ void heapInsert(Heap* heap, HeapNode* newnode) {
}
void
heapRemove
(
Heap
*
heap
,
HeapNode
*
node
)
{
HeapNode
*
smallest
;
HeapNode
*
smallest
;
HeapNode
**
max
;
HeapNode
*
child
;
u
nsigned
int
path
;
u
nsigned
int
k
;
u
nsigned
int
n
;
HeapNode
*
child
;
u
int32_t
path
;
u
int32_t
k
;
u
int32_t
n
;
if
(
heap
->
nelts
==
0
)
return
;
if
(
heap
->
nelts
==
0
)
return
;
/* Calculate the path from the min (the root) to the max, the left-most node
* of the bottom row.
*/
path
=
0
;
for
(
k
=
0
,
n
=
heap
->
nelts
;
n
>=
2
;
k
+=
1
,
n
/=
2
)
path
=
(
path
<<
1
)
|
(
n
&
1
);
for
(
k
=
0
,
n
=
heap
->
nelts
;
n
>=
2
;
k
+=
1
,
n
/=
2
)
path
=
(
path
<<
1
)
|
(
n
&
1
);
/* Now traverse the heap using the path we calculated in the previous step. */
max
=
&
heap
->
min
;
...
...
@@ -182,12 +173,9 @@ void heapRemove(Heap* heap, HeapNode* node) {
*/
for
(;;)
{
smallest
=
child
;
if
(
child
->
left
!=
NULL
&&
(
heap
->
compFn
)(
child
->
left
,
smallest
))
smallest
=
child
->
left
;
if
(
child
->
right
!=
NULL
&&
(
heap
->
compFn
)(
child
->
right
,
smallest
))
smallest
=
child
->
right
;
if
(
smallest
==
child
)
break
;
if
(
child
->
left
!=
NULL
&&
(
heap
->
compFn
)(
child
->
left
,
smallest
))
smallest
=
child
->
left
;
if
(
child
->
right
!=
NULL
&&
(
heap
->
compFn
)(
child
->
right
,
smallest
))
smallest
=
child
->
right
;
if
(
smallest
==
child
)
break
;
heapNodeSwap
(
heap
,
child
,
smallest
);
}
...
...
@@ -195,12 +183,7 @@ void heapRemove(Heap* heap, HeapNode* node) {
* this is required, because `max` node is not guaranteed to be the
* actual maximum in tree
*/
while
(
child
->
parent
!=
NULL
&&
(
heap
->
compFn
)(
child
,
child
->
parent
))
heapNodeSwap
(
heap
,
child
->
parent
,
child
);
}
void
heapDequeue
(
Heap
*
heap
)
{
heapRemove
(
heap
,
heap
->
min
);
while
(
child
->
parent
!=
NULL
&&
(
heap
->
compFn
)(
child
,
child
->
parent
))
heapNodeSwap
(
heap
,
child
->
parent
,
child
);
}
void
heapDequeue
(
Heap
*
heap
)
{
heapRemove
(
heap
,
heap
->
min
);
}
source/util/src/tidpool.c
浏览文件 @
cb71affe
...
...
@@ -13,17 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "tlog.h"
typedef
struct
{
int
maxId
;
int
numOfFree
;
int
freeSlot
;
bool
*
freeList
;
int
32_t
maxId
;
int
32_t
numOfFree
;
int
32_t
freeSlot
;
bool
*
freeList
;
pthread_mutex_t
mutex
;
}
id_pool_t
;
void
*
taosInitIdPool
(
int
maxId
)
{
void
*
taosInitIdPool
(
int
32_t
maxId
)
{
id_pool_t
*
pIdPool
=
calloc
(
1
,
sizeof
(
id_pool_t
));
if
(
pIdPool
==
NULL
)
return
NULL
;
...
...
@@ -44,17 +45,17 @@ void *taosInitIdPool(int maxId) {
return
pIdPool
;
}
int
taosAllocateId
(
void
*
handle
)
{
int
32_t
taosAllocateId
(
void
*
handle
)
{
id_pool_t
*
pIdPool
=
handle
;
if
(
handle
==
NULL
)
{
return
-
1
;
}
int
slot
=
-
1
;
int
32_t
slot
=
-
1
;
pthread_mutex_lock
(
&
pIdPool
->
mutex
);
if
(
pIdPool
->
numOfFree
>
0
)
{
for
(
int
i
=
0
;
i
<
pIdPool
->
maxId
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
pIdPool
->
maxId
;
++
i
)
{
slot
=
(
i
+
pIdPool
->
freeSlot
)
%
pIdPool
->
maxId
;
if
(
!
pIdPool
->
freeList
[
slot
])
{
pIdPool
->
freeList
[
slot
]
=
true
;
...
...
@@ -69,13 +70,13 @@ int taosAllocateId(void *handle) {
return
slot
+
1
;
}
void
taosFreeId
(
void
*
handle
,
int
id
)
{
void
taosFreeId
(
void
*
handle
,
int
32_t
id
)
{
id_pool_t
*
pIdPool
=
handle
;
if
(
handle
==
NULL
)
return
;
pthread_mutex_lock
(
&
pIdPool
->
mutex
);
int
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
int
32_t
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
if
(
pIdPool
->
freeList
[
slot
])
{
pIdPool
->
freeList
[
slot
]
=
false
;
pIdPool
->
numOfFree
++
;
...
...
@@ -100,22 +101,22 @@ void taosIdPoolCleanUp(void *handle) {
free
(
pIdPool
);
}
int
taosIdPoolNumOfUsed
(
void
*
handle
)
{
int
32_t
taosIdPoolNumOfUsed
(
void
*
handle
)
{
id_pool_t
*
pIdPool
=
handle
;
pthread_mutex_lock
(
&
pIdPool
->
mutex
);
int
ret
=
pIdPool
->
maxId
-
pIdPool
->
numOfFree
;
int
32_t
ret
=
pIdPool
->
maxId
-
pIdPool
->
numOfFree
;
pthread_mutex_unlock
(
&
pIdPool
->
mutex
);
return
ret
;
}
bool
taosIdPoolMarkStatus
(
void
*
handle
,
int
id
)
{
bool
ret
=
false
;
bool
taosIdPoolMarkStatus
(
void
*
handle
,
int
32_t
id
)
{
bool
ret
=
false
;
id_pool_t
*
pIdPool
=
handle
;
pthread_mutex_lock
(
&
pIdPool
->
mutex
);
int
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
int
32_t
slot
=
(
id
-
1
)
%
pIdPool
->
maxId
;
if
(
!
pIdPool
->
freeList
[
slot
])
{
pIdPool
->
freeList
[
slot
]
=
true
;
pIdPool
->
numOfFree
--
;
...
...
@@ -128,8 +129,8 @@ bool taosIdPoolMarkStatus(void *handle, int id) {
return
ret
;
}
int
taosUpdateIdPool
(
id_pool_t
*
handle
,
in
t
maxId
)
{
id_pool_t
*
pIdPool
=
(
id_pool_t
*
)
handle
;
int
32_t
taosUpdateIdPool
(
id_pool_t
*
handle
,
int32_
t
maxId
)
{
id_pool_t
*
pIdPool
=
(
id_pool_t
*
)
handle
;
if
(
maxId
<=
pIdPool
->
maxId
)
{
return
0
;
}
...
...
@@ -154,11 +155,11 @@ int taosUpdateIdPool(id_pool_t *handle, int maxId) {
return
0
;
}
int
taosIdPoolMaxSize
(
void
*
handle
)
{
int
32_t
taosIdPoolMaxSize
(
void
*
handle
)
{
id_pool_t
*
pIdPool
=
(
id_pool_t
*
)
handle
;
pthread_mutex_lock
(
&
pIdPool
->
mutex
);
int
ret
=
pIdPool
->
maxId
;
int
32_t
ret
=
pIdPool
->
maxId
;
pthread_mutex_unlock
(
&
pIdPool
->
mutex
);
return
ret
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录