Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c7e5ee34
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
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看板
提交
c7e5ee34
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tarray
上级
426519d6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
75 addition
and
73 deletion
+75
-73
include/util/tarray.h
include/util/tarray.h
+12
-12
include/util/texception.h
include/util/texception.h
+0
-2
include/util/tlist.h
include/util/tlist.h
+1
-0
source/util/src/tarray.c
source/util/src/tarray.c
+62
-59
未找到文件。
include/util/tarray.h
浏览文件 @
c7e5ee34
...
...
@@ -16,13 +16,13 @@
#ifndef _TD_UTIL_ARRAY_H
#define _TD_UTIL_ARRAY_H
#include "os.h"
#include "talgo.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#include "os.h"
#include "talgo.h"
#if 0
#define TARRAY(TYPE) \
struct { \
...
...
@@ -31,15 +31,15 @@ extern "C" {
struct TYPE* td_array_data_; \
}
#define TARRAY_SIZE(ARRAY) (ARRAY)->tarray_size_
#define TARRAY_NELES(ARRAY) (ARRAY)->tarray_neles_
#define TARRAY_SIZE(ARRAY)
(ARRAY)->tarray_size_
#define TARRAY_NELES(ARRAY)
(ARRAY)->tarray_neles_
#define TARRAY_ELE_AT(ARRAY, IDX) ((ARRAY)->td_array_data_ + idx)
#endif
#define TARRAY_MIN_SIZE 8
#define TARRAY_MIN_SIZE
8
#define TARRAY_GET_ELEM(array, index) ((void*)((char*)((array)->pData) + (index) * (array)->elemSize))
#define TARRAY_ELEM_IDX(array, ele) (POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
#define TARRAY_GET_START(array) ((array)->pData)
#define TARRAY_ELEM_IDX(array, ele)
(POINTER_DISTANCE(ele, (array)->pData) / (array)->elemSize)
#define TARRAY_GET_START(array)
((array)->pData)
typedef
struct
SArray
{
size_t
size
;
...
...
@@ -70,7 +70,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t tsize);
* @param nEles
* @return
*/
void
*
taosArrayAddBatch
(
SArray
*
pArray
,
const
void
*
pData
,
int
nEles
);
void
*
taosArrayAddBatch
(
SArray
*
pArray
,
const
void
*
pData
,
int
32_t
nEles
);
/**
*
...
...
@@ -238,7 +238,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn);
* @param compar
* @param key
*/
void
*
taosArraySearch
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
flags
);
void
*
taosArraySearch
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
32_t
flags
);
/**
* search the array, return index of the element
...
...
@@ -246,14 +246,14 @@ void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t compa
* @param compar
* @param key
*/
int32_t
taosArraySearchIdx
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
flags
);
int32_t
taosArraySearchIdx
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
32_t
flags
);
/**
* search the array
* @param pArray
* @param key
*/
char
*
taosArraySearchString
(
const
SArray
*
pArray
,
const
char
*
key
,
__compar_fn_t
comparFn
,
int
flags
);
char
*
taosArraySearchString
(
const
SArray
*
pArray
,
const
char
*
key
,
__compar_fn_t
comparFn
,
int
32_t
flags
);
/**
* sort the pointer data in the array
...
...
include/util/texception.h
浏览文件 @
c7e5ee34
...
...
@@ -61,7 +61,6 @@ typedef struct SExceptionNode {
SCleanupAction
*
cleanupActions
;
}
SExceptionNode
;
////////////////////////////////////////////////////////////////////////////////
// functions & macros for auto-cleanup
void
cleanupPush_void_ptr_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
void
*
arg2
);
...
...
@@ -92,7 +91,6 @@ bool cleanupExceedLimit();
#define CLEANUP_EXECUTE_TO(anchor, failed) cleanupExecuteTo((anchor), (failed))
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
////////////////////////////////////////////////////////////////////////////////
// functions & macros for exception handling
void
exceptionPushNode
(
SExceptionNode
*
node
);
...
...
include/util/tlist.h
浏览文件 @
c7e5ee34
...
...
@@ -12,6 +12,7 @@
* 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 _TD_UTIL_LIST_H_
#define _TD_UTIL_LIST_H_
...
...
source/util/src/tarray.c
浏览文件 @
c7e5ee34
...
...
@@ -13,9 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#
include "os.h"
#
define _DEFAULT_SOURCE
#include "tarray.h"
#include "talgo.h"
SArray
*
taosArrayInit
(
size_t
size
,
size_t
elemSize
)
{
assert
(
elemSize
>
0
);
...
...
@@ -54,7 +53,7 @@ static int32_t taosArrayResize(SArray* pArray) {
pArray
->
pData
=
tmp
;
pArray
->
capacity
=
size
;
return
0
;
}
...
...
@@ -75,12 +74,12 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t newCap) {
return
0
;
}
void
*
taosArrayAddBatch
(
SArray
*
pArray
,
const
void
*
pData
,
int
nEles
)
{
void
*
taosArrayAddBatch
(
SArray
*
pArray
,
const
void
*
pData
,
int
32_t
nEles
)
{
if
(
pArray
==
NULL
||
pData
==
NULL
)
{
return
NULL
;
}
if
(
taosArrayEnsureCap
(
pArray
,
pArray
->
size
+
nEles
)
!=
0
)
{
if
(
taosArrayEnsureCap
(
pArray
,
pArray
->
size
+
nEles
)
!=
0
)
{
return
NULL
;
}
...
...
@@ -91,7 +90,7 @@ void* taosArrayAddBatch(SArray* pArray, const void* pData, int nEles) {
return
dst
;
}
void
taosArrayRemoveBatch
(
SArray
*
pArray
,
const
int32_t
*
pData
,
int32_t
numOfElems
)
{
void
taosArrayRemoveBatch
(
SArray
*
pArray
,
const
int32_t
*
pData
,
int32_t
numOfElems
)
{
assert
(
pArray
!=
NULL
&&
pData
!=
NULL
);
if
(
numOfElems
<=
0
)
{
return
;
...
...
@@ -104,7 +103,7 @@ void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfEle
}
int32_t
i
=
pData
[
0
]
+
1
,
j
=
0
;
while
(
i
<
size
)
{
while
(
i
<
size
)
{
if
(
j
==
numOfElems
-
1
)
{
break
;
}
...
...
@@ -133,7 +132,7 @@ void taosArrayRemoveBatch(SArray *pArray, const int32_t* pData, int32_t numOfEle
pArray
->
size
-=
numOfElems
;
}
void
taosArrayRemoveDuplicate
(
SArray
*
pArray
,
__compar_fn_t
comparFn
,
void
(
*
fp
)(
void
*
))
{
void
taosArrayRemoveDuplicate
(
SArray
*
pArray
,
__compar_fn_t
comparFn
,
void
(
*
fp
)(
void
*
))
{
assert
(
pArray
);
size_t
size
=
pArray
->
size
;
...
...
@@ -142,7 +141,7 @@ void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)
}
int32_t
pos
=
0
;
for
(
int32_t
i
=
1
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
1
;
i
<
size
;
++
i
)
{
char
*
p1
=
taosArrayGet
(
pArray
,
pos
);
char
*
p2
=
taosArrayGet
(
pArray
,
i
);
...
...
@@ -164,7 +163,7 @@ void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)
}
if
(
fp
!=
NULL
)
{
for
(
int32_t
i
=
pos
+
1
;
i
<
pArray
->
size
;
++
i
)
{
for
(
int32_t
i
=
pos
+
1
;
i
<
pArray
->
size
;
++
i
)
{
void
*
p
=
taosArrayGet
(
pArray
,
i
);
fp
(
p
);
}
...
...
@@ -174,11 +173,11 @@ void taosArrayRemoveDuplicate(SArray *pArray, __compar_fn_t comparFn, void (*fp)
}
void
*
taosArrayAddAll
(
SArray
*
pArray
,
const
SArray
*
pInput
)
{
return
taosArrayAddBatch
(
pArray
,
pInput
->
pData
,
(
int32_t
)
taosArrayGetSize
(
pInput
));
return
taosArrayAddBatch
(
pArray
,
pInput
->
pData
,
(
int32_t
)
taosArrayGetSize
(
pInput
));
}
void
*
taosArrayPop
(
SArray
*
pArray
)
{
assert
(
pArray
!=
NULL
);
assert
(
pArray
!=
NULL
);
if
(
pArray
->
size
==
0
)
{
return
NULL
;
...
...
@@ -194,15 +193,13 @@ void* taosArrayGet(const SArray* pArray, size_t index) {
void
*
taosArrayGetP
(
const
SArray
*
pArray
,
size_t
index
)
{
assert
(
index
<
pArray
->
size
);
void
*
d
=
TARRAY_GET_ELEM
(
pArray
,
index
);
return
*
(
void
**
)
d
;
}
void
*
taosArrayGetLast
(
const
SArray
*
pArray
)
{
return
TARRAY_GET_ELEM
(
pArray
,
pArray
->
size
-
1
);
}
void
*
taosArrayGetLast
(
const
SArray
*
pArray
)
{
return
TARRAY_GET_ELEM
(
pArray
,
pArray
->
size
-
1
);
}
size_t
taosArrayGetSize
(
const
SArray
*
pArray
)
{
if
(
pArray
==
NULL
)
{
...
...
@@ -227,7 +224,7 @@ void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
if
(
pArray
->
size
>=
pArray
->
capacity
)
{
int32_t
ret
=
taosArrayResize
(
pArray
);
if
(
ret
<
0
)
{
return
NULL
;
}
...
...
@@ -240,7 +237,7 @@ void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
memcpy
(
dst
,
pData
,
pArray
->
elemSize
);
pArray
->
size
+=
1
;
return
dst
;
}
...
...
@@ -252,7 +249,7 @@ void taosArraySet(SArray* pArray, size_t index, void* pData) {
void
taosArrayPopFrontBatch
(
SArray
*
pArray
,
size_t
cnt
)
{
assert
(
cnt
<=
pArray
->
size
);
pArray
->
size
=
pArray
->
size
-
cnt
;
if
(
pArray
->
size
==
0
)
{
if
(
pArray
->
size
==
0
)
{
return
;
}
memmove
(
pArray
->
pData
,
(
char
*
)
pArray
->
pData
+
cnt
*
pArray
->
elemSize
,
pArray
->
size
*
pArray
->
elemSize
);
...
...
@@ -265,14 +262,15 @@ void taosArrayPopTailBatch(SArray* pArray, size_t cnt) {
void
taosArrayRemove
(
SArray
*
pArray
,
size_t
index
)
{
assert
(
index
<
pArray
->
size
);
if
(
index
==
pArray
->
size
-
1
)
{
taosArrayPop
(
pArray
);
return
;
}
size_t
remain
=
pArray
->
size
-
index
-
1
;
memmove
((
char
*
)
pArray
->
pData
+
index
*
pArray
->
elemSize
,
(
char
*
)
pArray
->
pData
+
(
index
+
1
)
*
pArray
->
elemSize
,
remain
*
pArray
->
elemSize
);
memmove
((
char
*
)
pArray
->
pData
+
index
*
pArray
->
elemSize
,
(
char
*
)
pArray
->
pData
+
(
index
+
1
)
*
pArray
->
elemSize
,
remain
*
pArray
->
elemSize
);
pArray
->
size
-=
1
;
}
...
...
@@ -288,13 +286,13 @@ SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize) {
SArray
*
taosArrayDup
(
const
SArray
*
pSrc
)
{
assert
(
pSrc
!=
NULL
);
if
(
pSrc
->
size
==
0
)
{
// empty array list
if
(
pSrc
->
size
==
0
)
{
// empty array list
return
taosArrayInit
(
8
,
pSrc
->
elemSize
);
}
SArray
*
dst
=
taosArrayInit
(
pSrc
->
size
,
pSrc
->
elemSize
);
memcpy
(
dst
->
pData
,
pSrc
->
pData
,
pSrc
->
elemSize
*
pSrc
->
size
);
dst
->
size
=
pSrc
->
size
;
return
dst
;
...
...
@@ -324,7 +322,7 @@ void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*)) {
return
;
}
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
fp
(
TARRAY_GET_ELEM
(
pArray
,
i
));
}
...
...
@@ -338,14 +336,14 @@ void taosArraySort(SArray* pArray, __compar_fn_t compar) {
qsort
(
pArray
->
pData
,
pArray
->
size
,
pArray
->
elemSize
,
compar
);
}
void
*
taosArraySearch
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
flags
)
{
void
*
taosArraySearch
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
32_t
flags
)
{
assert
(
pArray
!=
NULL
&&
comparFn
!=
NULL
);
assert
(
key
!=
NULL
);
return
taosbsearch
(
key
,
pArray
->
pData
,
pArray
->
size
,
pArray
->
elemSize
,
comparFn
,
flags
);
}
int32_t
taosArraySearchIdx
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
flags
)
{
int32_t
taosArraySearchIdx
(
const
SArray
*
pArray
,
const
void
*
key
,
__compar_fn_t
comparFn
,
int
32_t
flags
)
{
void
*
item
=
taosArraySearch
(
pArray
,
key
,
comparFn
,
flags
);
return
item
==
NULL
?
-
1
:
(
int32_t
)((
char
*
)
item
-
(
char
*
)
pArray
->
pData
)
/
pArray
->
elemSize
;
}
...
...
@@ -355,7 +353,7 @@ void taosArraySortString(SArray* pArray, __compar_fn_t comparFn) {
qsort
(
pArray
->
pData
,
pArray
->
size
,
pArray
->
elemSize
,
comparFn
);
}
char
*
taosArraySearchString
(
const
SArray
*
pArray
,
const
char
*
key
,
__compar_fn_t
comparFn
,
int
flags
)
{
char
*
taosArraySearchString
(
const
SArray
*
pArray
,
const
char
*
key
,
__compar_fn_t
comparFn
,
int
32_t
flags
)
{
assert
(
pArray
!=
NULL
);
assert
(
key
!=
NULL
);
...
...
@@ -366,47 +364,53 @@ char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t
return
*
(
char
**
)
p
;
}
static
int
taosArrayPartition
(
SArray
*
pArray
,
int
i
,
int
j
,
__ext_compar_fn_t
fn
,
const
void
*
userData
)
{
void
*
key
=
taosArrayGetP
(
pArray
,
i
);
static
int
32_t
taosArrayPartition
(
SArray
*
pArray
,
int32_t
i
,
int32_t
j
,
__ext_compar_fn_t
fn
,
const
void
*
userData
)
{
void
*
key
=
taosArrayGetP
(
pArray
,
i
);
while
(
i
<
j
)
{
while
(
i
<
j
&&
fn
(
taosArrayGetP
(
pArray
,
j
),
key
,
userData
)
>=
0
)
{
j
--
;
}
if
(
i
<
j
)
{
void
*
a
=
taosArrayGetP
(
pArray
,
j
);
while
(
i
<
j
&&
fn
(
taosArrayGetP
(
pArray
,
j
),
key
,
userData
)
>=
0
)
{
j
--
;
}
if
(
i
<
j
)
{
void
*
a
=
taosArrayGetP
(
pArray
,
j
);
taosArraySet
(
pArray
,
i
,
&
a
);
}
while
(
i
<
j
&&
fn
(
taosArrayGetP
(
pArray
,
i
),
key
,
userData
)
<=
0
)
{
i
++
;}
while
(
i
<
j
&&
fn
(
taosArrayGetP
(
pArray
,
i
),
key
,
userData
)
<=
0
)
{
i
++
;
}
if
(
i
<
j
)
{
void
*
a
=
taosArrayGetP
(
pArray
,
i
);
void
*
a
=
taosArrayGetP
(
pArray
,
i
);
taosArraySet
(
pArray
,
j
,
&
a
);
}
}
taosArraySet
(
pArray
,
i
,
&
key
);
taosArraySet
(
pArray
,
i
,
&
key
);
return
i
;
}
static
void
taosArrayQuicksortHelper
(
SArray
*
pArray
,
int
low
,
int
high
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
static
void
taosArrayQuicksortHelper
(
SArray
*
pArray
,
int32_t
low
,
int32_t
high
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
if
(
low
<
high
)
{
int
idx
=
taosArrayPartition
(
pArray
,
low
,
high
,
fn
,
param
);
int
32_t
idx
=
taosArrayPartition
(
pArray
,
low
,
high
,
fn
,
param
);
taosArrayQuicksortHelper
(
pArray
,
low
,
idx
-
1
,
fn
,
param
);
taosArrayQuicksortHelper
(
pArray
,
idx
+
1
,
high
,
fn
,
param
);
}
}
}
static
void
taosArrayQuickSort
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
static
void
taosArrayQuickSort
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
if
(
pArray
->
size
<=
1
)
{
return
;
}
taosArrayQuicksortHelper
(
pArray
,
0
,
(
int
)(
taosArrayGetSize
(
pArray
)
-
1
),
fn
,
param
);
}
taosArrayQuicksortHelper
(
pArray
,
0
,
(
int
32_t
)(
taosArrayGetSize
(
pArray
)
-
1
),
fn
,
param
);
}
static
void
taosArrayInsertSort
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
static
void
taosArrayInsertSort
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
if
(
pArray
->
size
<=
1
)
{
return
;
}
for
(
int
i
=
1
;
i
<=
pArray
->
size
-
1
;
++
i
)
{
for
(
int
j
=
i
;
j
>
0
;
--
j
)
{
}
for
(
int
32_t
i
=
1
;
i
<=
pArray
->
size
-
1
;
++
i
)
{
for
(
int
32_t
j
=
i
;
j
>
0
;
--
j
)
{
if
(
fn
(
taosArrayGetP
(
pArray
,
j
),
taosArrayGetP
(
pArray
,
j
-
1
),
param
)
==
-
1
)
{
void
*
a
=
taosArrayGetP
(
pArray
,
j
);
void
*
b
=
taosArrayGetP
(
pArray
,
j
-
1
);
void
*
a
=
taosArrayGetP
(
pArray
,
j
);
void
*
b
=
taosArrayGetP
(
pArray
,
j
-
1
);
taosArraySet
(
pArray
,
j
-
1
,
&
a
);
taosArraySet
(
pArray
,
j
,
&
b
);
}
else
{
...
...
@@ -415,11 +419,10 @@ static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void
}
}
return
;
}
// order array<type *>
void
taosArraySortPWithExt
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
taosArrayGetSize
(
pArray
)
>
8
?
taosArrayQuickSort
(
pArray
,
fn
,
param
)
:
taosArrayInsertSort
(
pArray
,
fn
,
param
);
}
//TODO(yihaoDeng) add order array<type>
}
// order array<type *>
void
taosArraySortPWithExt
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
)
{
taosArrayGetSize
(
pArray
)
>
8
?
taosArrayQuickSort
(
pArray
,
fn
,
param
)
:
taosArrayInsertSort
(
pArray
,
fn
,
param
);
}
// TODO(yihaoDeng) add order array<type>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录