Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
bb088704
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bb088704
编写于
5月 21, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-288]
上级
48da3c69
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
177 addition
and
189 deletion
+177
-189
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+13
-13
src/client/src/tscProfile.c
src/client/src/tscProfile.c
+0
-2
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+16
-7
src/query/src/qtokenizer.c
src/query/src/qtokenizer.c
+2
-116
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+1
-0
src/util/inc/tstoken.h
src/util/inc/tstoken.h
+109
-4
src/util/src/hash.c
src/util/src/hash.c
+26
-28
src/util/src/thashutil.c
src/util/src/thashutil.c
+10
-19
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
bb088704
...
@@ -42,35 +42,35 @@ enum {
...
@@ -42,35 +42,35 @@ enum {
static
int32_t
tscAllocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
);
static
int32_t
tscAllocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
);
static
int32_t
tscToInteger
(
SSQLToken
*
pToken
,
int64_t
*
value
,
char
**
endPtr
)
{
static
int32_t
tscToInteger
(
SSQLToken
*
pToken
,
int64_t
*
value
,
char
**
endPtr
)
{
int32_t
numType
=
isValidNumber
(
pToken
);
//
int32_t numType = isValidNumber(pToken);
if
(
TK_ILLEGAL
==
numType
)
{
//
if (TK_ILLEGAL == numType) {
return
numType
;
//
return numType;
}
//
}
int32_t
radix
=
10
;
int32_t
radix
=
10
;
if
(
numT
ype
==
TK_HEX
)
{
if
(
pToken
->
t
ype
==
TK_HEX
)
{
radix
=
16
;
radix
=
16
;
}
else
if
(
numT
ype
==
TK_OCT
)
{
}
else
if
(
pToken
->
t
ype
==
TK_OCT
)
{
radix
=
8
;
radix
=
8
;
}
else
if
(
numT
ype
==
TK_BIN
)
{
}
else
if
(
pToken
->
t
ype
==
TK_BIN
)
{
radix
=
2
;
radix
=
2
;
}
}
errno
=
0
;
errno
=
0
;
*
value
=
strtoll
(
pToken
->
z
,
endPtr
,
radix
);
*
value
=
strtoll
(
pToken
->
z
,
endPtr
,
radix
);
return
numT
ype
;
return
pToken
->
t
ype
;
}
}
static
int32_t
tscToDouble
(
SSQLToken
*
pToken
,
double
*
value
,
char
**
endPtr
)
{
static
int32_t
tscToDouble
(
SSQLToken
*
pToken
,
double
*
value
,
char
**
endPtr
)
{
int32_t
numType
=
isValidNumber
(
pToken
);
//
int32_t numType = isValidNumber(pToken);
if
(
TK_ILLEGAL
==
numType
)
{
//
if (TK_ILLEGAL == numType) {
return
numType
;
//
return numType;
}
//
}
errno
=
0
;
errno
=
0
;
*
value
=
strtod
(
pToken
->
z
,
endPtr
);
*
value
=
strtod
(
pToken
->
z
,
endPtr
);
return
numT
ype
;
return
pToken
->
t
ype
;
}
}
int
tsParseTime
(
SSQLToken
*
pToken
,
int64_t
*
time
,
char
**
next
,
char
*
error
,
int16_t
timePrec
)
{
int
tsParseTime
(
SSQLToken
*
pToken
,
int64_t
*
time
,
char
**
next
,
char
*
error
,
int16_t
timePrec
)
{
...
...
src/client/src/tscProfile.c
浏览文件 @
bb088704
...
@@ -23,8 +23,6 @@
...
@@ -23,8 +23,6 @@
void
tscSaveSlowQueryFp
(
void
*
handle
,
void
*
tmrId
);
void
tscSaveSlowQueryFp
(
void
*
handle
,
void
*
tmrId
);
void
*
tscSlowQueryConn
=
NULL
;
void
*
tscSlowQueryConn
=
NULL
;
bool
tscSlowQueryConnInitialized
=
false
;
bool
tscSlowQueryConnInitialized
=
false
;
TAOS
*
taos_connect_a
(
char
*
ip
,
char
*
user
,
char
*
pass
,
char
*
db
,
uint16_t
port
,
void
(
*
fp
)(
void
*
,
TAOS_RES
*
,
int
),
void
*
param
,
void
**
taos
);
void
tscInitConnCb
(
void
*
param
,
TAOS_RES
*
result
,
int
code
)
{
void
tscInitConnCb
(
void
*
param
,
TAOS_RES
*
result
,
int
code
)
{
char
*
sql
=
param
;
char
*
sql
=
param
;
...
...
src/query/src/qExecutor.c
浏览文件 @
bb088704
...
@@ -288,8 +288,14 @@ void updateNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOfRes) {
...
@@ -288,8 +288,14 @@ void updateNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOfRes) {
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
SResultInfo
*
pResInfo
=
GET_RES_INFO
(
&
pRuntimeEnv
->
pCtx
[
j
]);
SResultInfo
*
pResInfo
=
GET_RES_INFO
(
&
pRuntimeEnv
->
pCtx
[
j
]);
assert
(
pResInfo
->
numOfRes
>
numOfRes
);
int16_t
functionId
=
pRuntimeEnv
->
pCtx
[
j
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TS
||
functionId
==
TSDB_FUNC_TAG
||
functionId
==
TSDB_FUNC_TAGPRJ
||
functionId
==
TSDB_FUNC_TS_DUMMY
)
{
continue
;
}
assert
(
pResInfo
->
numOfRes
>
numOfRes
);
pResInfo
->
numOfRes
=
numOfRes
;
pResInfo
->
numOfRes
=
numOfRes
;
}
}
}
}
...
@@ -1318,6 +1324,10 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
...
@@ -1318,6 +1324,10 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
if
(
numOfRes
>=
pQuery
->
rec
.
threshold
)
{
if
(
numOfRes
>=
pQuery
->
rec
.
threshold
)
{
setQueryStatus
(
pQuery
,
QUERY_RESBUF_FULL
);
setQueryStatus
(
pQuery
,
QUERY_RESBUF_FULL
);
}
}
if
(
numOfRes
>=
pQuery
->
limit
.
limit
+
pQuery
->
limit
.
offset
)
{
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
}
}
}
return
numOfRes
;
return
numOfRes
;
...
@@ -3197,7 +3207,7 @@ void skipResults(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3197,7 +3207,7 @@ void skipResults(SQueryRuntimeEnv *pRuntimeEnv) {
resetCtxOutputBuf
(
pRuntimeEnv
);
resetCtxOutputBuf
(
pRuntimeEnv
);
// clear the buffer
is
full flag if exists
// clear the buffer full flag if exists
CLEAR_QUERY_STATUS
(
pQuery
,
QUERY_RESBUF_FULL
);
CLEAR_QUERY_STATUS
(
pQuery
,
QUERY_RESBUF_FULL
);
}
else
{
}
else
{
int64_t
numOfSkip
=
pQuery
->
limit
.
offset
;
int64_t
numOfSkip
=
pQuery
->
limit
.
offset
;
...
@@ -3211,14 +3221,15 @@ void skipResults(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3211,14 +3221,15 @@ void skipResults(SQueryRuntimeEnv *pRuntimeEnv) {
int32_t
functionId
=
pQuery
->
pSelectExpr
[
i
].
base
.
functionId
;
int32_t
functionId
=
pQuery
->
pSelectExpr
[
i
].
base
.
functionId
;
int32_t
bytes
=
pRuntimeEnv
->
pCtx
[
i
].
outputBytes
;
int32_t
bytes
=
pRuntimeEnv
->
pCtx
[
i
].
outputBytes
;
memmove
(
pQuery
->
sdata
[
i
]
->
data
,
pQuery
->
sdata
[
i
]
->
data
+
bytes
*
numOfSkip
,
pQuery
->
rec
.
rows
*
bytes
);
memmove
(
pQuery
->
sdata
[
i
]
->
data
,
(
char
*
)
pQuery
->
sdata
[
i
]
->
data
+
bytes
*
numOfSkip
,
pQuery
->
rec
.
rows
*
bytes
);
pRuntimeEnv
->
pCtx
[
i
].
aOutputBuf
=
pQuery
->
sdata
[
i
]
->
data
+
pQuery
->
rec
.
row
s
;
pRuntimeEnv
->
pCtx
[
i
].
aOutputBuf
=
((
char
*
)
pQuery
->
sdata
[
i
]
->
data
)
+
pQuery
->
rec
.
rows
*
byte
s
;
if
(
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
)
{
if
(
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
)
{
pRuntimeEnv
->
pCtx
[
i
].
ptsOutputBuf
=
pRuntimeEnv
->
pCtx
[
0
].
aOutputBuf
;
pRuntimeEnv
->
pCtx
[
i
].
ptsOutputBuf
=
pRuntimeEnv
->
pCtx
[
0
].
aOutputBuf
;
}
}
}
}
updateNumOfResult
(
pRuntimeEnv
,
pQuery
->
rec
.
rows
);
updateNumOfResult
(
pRuntimeEnv
,
pQuery
->
rec
.
rows
);
}
}
}
}
...
@@ -4649,10 +4660,8 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
...
@@ -4649,10 +4660,8 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
copyFromWindowResToSData
(
pQInfo
,
pWindowResInfo
->
pResult
);
copyFromWindowResToSData
(
pQInfo
,
pWindowResInfo
->
pResult
);
}
}
pQuery
->
rec
.
total
+=
pQuery
->
rec
.
rows
;
qTrace
(
qTrace
(
"QInfo %p
,
numOfTables:%d, index:%d, numOfGroups:%d, %d points returned, total:%"
PRId64
", offset:%"
PRId64
,
"QInfo %p numOfTables:%d, index:%d, numOfGroups:%d, %d points returned, total:%"
PRId64
", offset:%"
PRId64
,
pQInfo
,
pQInfo
->
groupInfo
.
numOfTables
,
pQInfo
->
tableIndex
,
numOfGroups
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
,
pQInfo
,
pQInfo
->
groupInfo
.
numOfTables
,
pQInfo
->
tableIndex
,
numOfGroups
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
,
pQuery
->
limit
.
offset
);
pQuery
->
limit
.
offset
);
}
}
...
...
src/query/src/qtokenizer.c
浏览文件 @
bb088704
...
@@ -282,11 +282,7 @@ int tSQLKeywordCode(const char* z, int n) {
...
@@ -282,11 +282,7 @@ int tSQLKeywordCode(const char* z, int n) {
}
}
SKeyword
**
pKey
=
(
SKeyword
**
)
taosHashGet
(
KeywordHashTable
,
key
,
n
);
SKeyword
**
pKey
=
(
SKeyword
**
)
taosHashGet
(
KeywordHashTable
,
key
,
n
);
if
(
pKey
!=
NULL
)
{
return
(
pKey
!=
NULL
)
?
(
*
pKey
)
->
type
:
TK_ID
;
return
(
*
pKey
)
->
type
;
}
else
{
return
TK_ID
;
}
}
}
/*
/*
...
@@ -662,114 +658,4 @@ SSQLToken tStrGetToken(char* str, int32_t* i, bool isPrevOptr, uint32_t numOfIgn
...
@@ -662,114 +658,4 @@ SSQLToken tStrGetToken(char* str, int32_t* i, bool isPrevOptr, uint32_t numOfIgn
return
t0
;
return
t0
;
}
}
FORCE_INLINE
bool
isKeyWord
(
const
char
*
z
,
int32_t
len
)
{
return
(
tSQLKeywordCode
((
char
*
)
z
,
len
)
!=
TK_ID
);
}
bool
isKeyWord
(
const
char
*
z
,
int32_t
len
)
{
return
(
tSQLKeywordCode
((
char
*
)
z
,
len
)
!=
TK_ID
);
}
\ No newline at end of file
FORCE_INLINE
bool
isNumber
(
const
SSQLToken
*
pToken
)
{
return
(
pToken
->
type
==
TK_INTEGER
||
pToken
->
type
==
TK_FLOAT
||
pToken
->
type
==
TK_HEX
||
pToken
->
type
==
TK_BIN
);
}
int32_t
isValidNumber
(
const
SSQLToken
*
pToken
)
{
const
char
*
z
=
pToken
->
z
;
int32_t
type
=
TK_ILLEGAL
;
int32_t
i
=
0
;
for
(;
i
<
pToken
->
n
;
++
i
)
{
switch
(
z
[
i
])
{
case
'+'
:
case
'-'
:
{
break
;
}
case
'.'
:
{
/*
* handle the the float number with out integer part
* .123
* .123e4
*/
if
(
!
isdigit
(
z
[
i
+
1
]))
{
return
TK_ILLEGAL
;
}
for
(
i
+=
2
;
isdigit
(
z
[
i
]);
i
++
)
{
}
if
((
z
[
i
]
==
'e'
||
z
[
i
]
==
'E'
)
&&
(
isdigit
(
z
[
i
+
1
])
||
((
z
[
i
+
1
]
==
'+'
||
z
[
i
+
1
]
==
'-'
)
&&
isdigit
(
z
[
i
+
2
]))))
{
i
+=
2
;
while
(
isdigit
(
z
[
i
]))
{
i
++
;
}
}
type
=
TK_FLOAT
;
goto
_end
;
}
case
'0'
:
{
char
next
=
z
[
i
+
1
];
if
(
next
==
'b'
)
{
// bin number
type
=
TK_BIN
;
for
(
i
+=
2
;
(
z
[
i
]
==
'0'
||
z
[
i
]
==
'1'
);
++
i
)
{
}
goto
_end
;
}
else
if
(
next
==
'x'
)
{
//hex number
type
=
TK_HEX
;
for
(
i
+=
2
;
isdigit
(
z
[
i
])
||
(
z
[
i
]
>=
'a'
&&
z
[
i
]
<=
'f'
)
||
(
z
[
i
]
>=
'A'
&&
z
[
i
]
<=
'F'
);
++
i
)
{
}
goto
_end
;
}
}
case
'1'
:
case
'2'
:
case
'3'
:
case
'4'
:
case
'5'
:
case
'6'
:
case
'7'
:
case
'8'
:
case
'9'
:
{
type
=
TK_INTEGER
;
for
(;
isdigit
(
z
[
i
]);
i
++
)
{
}
int32_t
seg
=
0
;
while
(
z
[
i
]
==
'.'
&&
isdigit
(
z
[
i
+
1
]))
{
i
+=
2
;
while
(
isdigit
(
z
[
i
]))
{
i
++
;
}
seg
++
;
type
=
TK_FLOAT
;
}
if
(
seg
>
1
)
{
return
TK_ILLEGAL
;
}
if
((
z
[
i
]
==
'e'
||
z
[
i
]
==
'E'
)
&&
(
isdigit
(
z
[
i
+
1
])
||
((
z
[
i
+
1
]
==
'+'
||
z
[
i
+
1
]
==
'-'
)
&&
isdigit
(
z
[
i
+
2
]))))
{
i
+=
2
;
while
(
isdigit
(
z
[
i
]))
{
i
++
;
}
type
=
TK_FLOAT
;
}
goto
_end
;
}
default:
return
TK_ILLEGAL
;
}
}
_end:
if
(
i
<
pToken
->
n
)
{
return
TK_ILLEGAL
;
}
else
{
return
type
;
}
}
\ No newline at end of file
src/tsdb/src/tsdbRead.c
浏览文件 @
bb088704
...
@@ -859,6 +859,7 @@ static void mergeDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInfo
...
@@ -859,6 +859,7 @@ static void mergeDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInfo
}
}
}
}
pos
+=
(
end
-
start
+
1
)
*
step
;
cur
->
blockCompleted
=
(((
pos
>=
endPos
||
cur
->
lastKey
>
pQueryHandle
->
window
.
ekey
)
&&
ASCENDING_ORDER_TRAVERSE
(
pQueryHandle
->
order
))
||
cur
->
blockCompleted
=
(((
pos
>=
endPos
||
cur
->
lastKey
>
pQueryHandle
->
window
.
ekey
)
&&
ASCENDING_ORDER_TRAVERSE
(
pQueryHandle
->
order
))
||
((
pos
<=
endPos
||
cur
->
lastKey
<
pQueryHandle
->
window
.
ekey
)
&&
!
ASCENDING_ORDER_TRAVERSE
(
pQueryHandle
->
order
)));
((
pos
<=
endPos
||
cur
->
lastKey
<
pQueryHandle
->
window
.
ekey
)
&&
!
ASCENDING_ORDER_TRAVERSE
(
pQueryHandle
->
order
)));
...
...
src/util/inc/tstoken.h
浏览文件 @
bb088704
...
@@ -21,6 +21,8 @@ extern "C" {
...
@@ -21,6 +21,8 @@ extern "C" {
#endif
#endif
#include "os.h"
#include "os.h"
#include "tutil.h"
#include "ttokendef.h"
#define TK_SPACE 200
#define TK_SPACE 200
#define TK_COMMENT 201
#define TK_COMMENT 201
...
@@ -31,7 +33,7 @@ extern "C" {
...
@@ -31,7 +33,7 @@ extern "C" {
#define TK_FILE 206
#define TK_FILE 206
#define TK_QUESTION 207 // denoting the placeholder of "?",when invoking statement bind query
#define TK_QUESTION 207 // denoting the placeholder of "?",when invoking statement bind query
#define TSQL_TBNAME "TBNAME"
#define TSQL_TBNAME
"TBNAME"
#define TSQL_TBNAME_L "tbname"
#define TSQL_TBNAME_L "tbname"
// used to denote the minimum unite in sql parsing
// used to denote the minimum unite in sql parsing
...
@@ -74,14 +76,117 @@ bool isKeyWord(const char *z, int32_t len);
...
@@ -74,14 +76,117 @@ bool isKeyWord(const char *z, int32_t len);
* @param pToken
* @param pToken
* @return
* @return
*/
*/
bool
isNumber
(
const
SSQLToken
*
pToken
);
#define isNumber(tk) \
((tk)->type == TK_INTEGER || (tk)->type == TK_FLOAT || (tk)->type == TK_HEX || (tk)->type == TK_BIN)
/**
/**
* check if it is a token or not
* check if it is a token or not
* @param pToken
* @param pToken
* @return token type, if it is not a number, TK_ILLEGAL will return
* @return
token type, if it is not a number, TK_ILLEGAL will return
*/
*/
int32_t
isValidNumber
(
const
SSQLToken
*
pToken
);
static
FORCE_INLINE
int32_t
isValidNumber
(
const
SSQLToken
*
pToken
)
{
const
char
*
z
=
pToken
->
z
;
int32_t
type
=
TK_ILLEGAL
;
int32_t
i
=
0
;
for
(;
i
<
pToken
->
n
;
++
i
)
{
switch
(
z
[
i
])
{
case
'+'
:
case
'-'
:
{
break
;
}
case
'.'
:
{
/*
* handle the the float number with out integer part
* .123
* .123e4
*/
if
(
!
isdigit
(
z
[
i
+
1
]))
{
return
TK_ILLEGAL
;
}
for
(
i
+=
2
;
isdigit
(
z
[
i
]);
i
++
)
{
}
if
((
z
[
i
]
==
'e'
||
z
[
i
]
==
'E'
)
&&
(
isdigit
(
z
[
i
+
1
])
||
((
z
[
i
+
1
]
==
'+'
||
z
[
i
+
1
]
==
'-'
)
&&
isdigit
(
z
[
i
+
2
]))))
{
i
+=
2
;
while
(
isdigit
(
z
[
i
]))
{
i
++
;
}
}
type
=
TK_FLOAT
;
goto
_end
;
}
case
'0'
:
{
char
next
=
z
[
i
+
1
];
if
(
next
==
'b'
)
{
// bin number
type
=
TK_BIN
;
for
(
i
+=
2
;
(
z
[
i
]
==
'0'
||
z
[
i
]
==
'1'
);
++
i
)
{
}
goto
_end
;
}
else
if
(
next
==
'x'
)
{
//hex number
type
=
TK_HEX
;
for
(
i
+=
2
;
isdigit
(
z
[
i
])
||
(
z
[
i
]
>=
'a'
&&
z
[
i
]
<=
'f'
)
||
(
z
[
i
]
>=
'A'
&&
z
[
i
]
<=
'F'
);
++
i
)
{
}
goto
_end
;
}
}
case
'1'
:
case
'2'
:
case
'3'
:
case
'4'
:
case
'5'
:
case
'6'
:
case
'7'
:
case
'8'
:
case
'9'
:
{
type
=
TK_INTEGER
;
for
(;
isdigit
(
z
[
i
]);
i
++
)
{
}
int32_t
seg
=
0
;
while
(
z
[
i
]
==
'.'
&&
isdigit
(
z
[
i
+
1
]))
{
i
+=
2
;
while
(
isdigit
(
z
[
i
]))
{
i
++
;
}
seg
++
;
type
=
TK_FLOAT
;
}
if
(
seg
>
1
)
{
return
TK_ILLEGAL
;
}
if
((
z
[
i
]
==
'e'
||
z
[
i
]
==
'E'
)
&&
(
isdigit
(
z
[
i
+
1
])
||
((
z
[
i
+
1
]
==
'+'
||
z
[
i
+
1
]
==
'-'
)
&&
isdigit
(
z
[
i
+
2
]))))
{
i
+=
2
;
while
(
isdigit
(
z
[
i
]))
{
i
++
;
}
type
=
TK_FLOAT
;
}
goto
_end
;
}
default:
return
TK_ILLEGAL
;
}
}
_end:
return
(
i
<
pToken
->
n
)
?
TK_ILLEGAL
:
type
;
}
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/util/src/hash.c
浏览文件 @
bb088704
...
@@ -102,7 +102,32 @@ static void doUpdateHashTable(SHashObj *pHashObj, SHashNode *pNode);
...
@@ -102,7 +102,32 @@ static void doUpdateHashTable(SHashObj *pHashObj, SHashNode *pNode);
* @param hashVal hash value by hash function
* @param hashVal hash value by hash function
* @return
* @return
*/
*/
static
SHashNode
*
doGetNodeFromHashTable
(
SHashObj
*
pHashObj
,
const
void
*
key
,
uint32_t
keyLen
,
uint32_t
*
hashVal
);
FORCE_INLINE
SHashNode
*
doGetNodeFromHashTable
(
SHashObj
*
pHashObj
,
const
void
*
key
,
uint32_t
keyLen
,
uint32_t
*
hashVal
)
{
uint32_t
hash
=
(
*
pHashObj
->
hashFp
)(
key
,
keyLen
);
int32_t
slot
=
HASH_INDEX
(
hash
,
pHashObj
->
capacity
);
SHashEntry
*
pEntry
=
pHashObj
->
hashList
[
slot
];
SHashNode
*
pNode
=
pEntry
->
next
;
while
(
pNode
)
{
if
((
pNode
->
keyLen
==
keyLen
)
&&
(
memcmp
(
pNode
->
key
,
key
,
keyLen
)
==
0
))
{
break
;
}
pNode
=
pNode
->
next
;
}
if
(
pNode
)
{
assert
(
HASH_INDEX
(
pNode
->
hashVal
,
pHashObj
->
capacity
)
==
slot
);
}
// return the calculated hash value, to avoid calculating it again in other functions
if
(
hashVal
!=
NULL
)
{
*
hashVal
=
hash
;
}
return
pNode
;
}
/**
/**
* Resize the hash list if the threshold is reached
* Resize the hash list if the threshold is reached
...
@@ -438,33 +463,6 @@ void doUpdateHashTable(SHashObj *pHashObj, SHashNode *pNode) {
...
@@ -438,33 +463,6 @@ void doUpdateHashTable(SHashObj *pHashObj, SHashNode *pNode) {
}
}
}
}
SHashNode
*
doGetNodeFromHashTable
(
SHashObj
*
pHashObj
,
const
void
*
key
,
uint32_t
keyLen
,
uint32_t
*
hashVal
)
{
uint32_t
hash
=
(
*
pHashObj
->
hashFp
)(
key
,
keyLen
);
int32_t
slot
=
HASH_INDEX
(
hash
,
pHashObj
->
capacity
);
SHashEntry
*
pEntry
=
pHashObj
->
hashList
[
slot
];
SHashNode
*
pNode
=
pEntry
->
next
;
while
(
pNode
)
{
if
((
pNode
->
keyLen
==
keyLen
)
&&
(
memcmp
(
pNode
->
key
,
key
,
keyLen
)
==
0
))
{
break
;
}
pNode
=
pNode
->
next
;
}
if
(
pNode
)
{
assert
(
HASH_INDEX
(
pNode
->
hashVal
,
pHashObj
->
capacity
)
==
slot
);
}
// return the calculated hash value, to avoid calculating it again in other functions
if
(
hashVal
!=
NULL
)
{
*
hashVal
=
hash
;
}
return
pNode
;
}
void
taosHashTableResize
(
SHashObj
*
pHashObj
)
{
void
taosHashTableResize
(
SHashObj
*
pHashObj
)
{
if
(
pHashObj
->
size
<
pHashObj
->
capacity
*
HASH_DEFAULT_LOAD_FACTOR
)
{
if
(
pHashObj
->
size
<
pHashObj
->
capacity
*
HASH_DEFAULT_LOAD_FACTOR
)
{
return
;
return
;
...
...
src/util/src/thashutil.c
浏览文件 @
bb088704
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#include "hashfunc.h"
#include "hashfunc.h"
#include "tutil.h"
#include "tutil.h"
#define ROTL32(x, r) ((x) << (r) | (x) >> (32 - (r)))
#define ROTL32(x, r) ((x) << (r) | (x) >> (32
u
- (r)))
#define FMIX32(h) \
#define FMIX32(h) \
do { \
do { \
...
@@ -20,12 +20,12 @@
...
@@ -20,12 +20,12 @@
(h) *= 0xc2b2ae35; \
(h) *= 0xc2b2ae35; \
(h) ^= (h) >> 16; \
(h) ^= (h) >> 16; \
} while (0)
} while (0)
static
void
MurmurHash3_32_s
(
const
void
*
key
,
int
len
,
uint32_t
seed
,
void
*
out
)
{
uint32_t
MurmurHash3_32
(
const
char
*
key
,
uint32_t
len
)
{
const
uint8_t
*
data
=
(
const
uint8_t
*
)
key
;
const
uint8_t
*
data
=
(
const
uint8_t
*
)
key
;
const
int
nblocks
=
len
/
4
;
const
int
nblocks
=
len
>>
2u
;
uint32_t
h1
=
seed
;
uint32_t
h1
=
0x12345678
;
const
uint32_t
c1
=
0xcc9e2d51
;
const
uint32_t
c1
=
0xcc9e2d51
;
const
uint32_t
c2
=
0x1b873593
;
const
uint32_t
c2
=
0x1b873593
;
...
@@ -36,11 +36,11 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
...
@@ -36,11 +36,11 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
uint32_t
k1
=
blocks
[
i
];
uint32_t
k1
=
blocks
[
i
];
k1
*=
c1
;
k1
*=
c1
;
k1
=
ROTL32
(
k1
,
15
);
k1
=
ROTL32
(
k1
,
15
u
);
k1
*=
c2
;
k1
*=
c2
;
h1
^=
k1
;
h1
^=
k1
;
h1
=
ROTL32
(
h1
,
13
);
h1
=
ROTL32
(
h1
,
13
u
);
h1
=
h1
*
5
+
0xe6546b64
;
h1
=
h1
*
5
+
0xe6546b64
;
}
}
...
@@ -48,7 +48,7 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
...
@@ -48,7 +48,7 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
uint32_t
k1
=
0
;
uint32_t
k1
=
0
;
switch
(
len
&
3
)
{
switch
(
len
&
3
u
)
{
case
3
:
case
3
:
k1
^=
tail
[
2
]
<<
16
;
k1
^=
tail
[
2
]
<<
16
;
case
2
:
case
2
:
...
@@ -56,7 +56,7 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
...
@@ -56,7 +56,7 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
case
1
:
case
1
:
k1
^=
tail
[
0
];
k1
^=
tail
[
0
];
k1
*=
c1
;
k1
*=
c1
;
k1
=
ROTL32
(
k1
,
15
);
k1
=
ROTL32
(
k1
,
15
u
);
k1
*=
c2
;
k1
*=
c2
;
h1
^=
k1
;
h1
^=
k1
;
};
};
...
@@ -65,16 +65,7 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
...
@@ -65,16 +65,7 @@ static void MurmurHash3_32_s(const void *key, int len, uint32_t seed, void *out)
FMIX32
(
h1
);
FMIX32
(
h1
);
*
(
uint32_t
*
)
out
=
h1
;
return
h1
;
}
uint32_t
MurmurHash3_32
(
const
char
*
key
,
uint32_t
len
)
{
const
int32_t
hashSeed
=
0x12345678
;
uint32_t
val
=
0
;
MurmurHash3_32_s
(
key
,
len
,
hashSeed
,
&
val
);
return
val
;
}
}
uint32_t
taosIntHash_32
(
const
char
*
key
,
uint32_t
UNUSED_PARAM
(
len
))
{
return
*
(
uint32_t
*
)
key
;
}
uint32_t
taosIntHash_32
(
const
char
*
key
,
uint32_t
UNUSED_PARAM
(
len
))
{
return
*
(
uint32_t
*
)
key
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录