Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
05f06e04
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看板
提交
05f06e04
编写于
5月 02, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact sl
上级
21333a9c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
301 addition
and
1 deletion
+301
-1
include/util/tskiplist2.h
include/util/tskiplist2.h
+159
-0
source/libs/tdb/test/tdbTest.cpp
source/libs/tdb/test/tdbTest.cpp
+3
-1
source/util/src/tskiplist2.c
source/util/src/tskiplist2.c
+139
-0
未找到文件。
include/util/tskiplist2.h
0 → 100644
浏览文件 @
05f06e04
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* 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_SKIPLIST2_H_
#define _TD_UTIL_SKIPLIST2_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#define SL_MAX_LEVEL 15
typedef
struct
SSkipList2
SSkipList2
;
typedef
struct
SSLCursor
SSLCursor
;
typedef
struct
SSLCfg
SSLCfg
;
typedef
int32_t
(
*
tslCmprFn
)(
const
void
*
pKey1
,
int32_t
nKey1
,
const
void
*
pKey2
,
int32_t
nKey2
);
// SSkipList2
int32_t
slOpen
(
const
SSLCfg
*
pCfg
,
SSkipList2
**
ppSl
);
int32_t
slClose
(
SSkipList2
*
pSl
);
// SSLCursor
int32_t
slcOpen
(
SSkipList2
*
pSl
,
SSLCursor
*
pSlc
);
int32_t
slcClose
(
SSLCursor
*
pSlc
);
int32_t
slcMoveTo
(
SSLCursor
*
pSlc
,
const
void
*
pKey
,
int32_t
nKey
);
int32_t
slcMoveToNext
(
SSLCursor
*
pSlc
);
int32_t
slcMoveToPrev
(
SSLCursor
*
pSlc
);
int32_t
slcMoveToFirst
(
SSLCursor
*
pSlc
);
int32_t
slcMoveToLast
(
SSLCursor
*
pSlc
);
int32_t
slcPut
(
SSLCursor
*
pSlc
,
const
void
*
pKey
,
int32_t
nKey
,
const
void
*
pData
,
int32_t
nData
);
int32_t
slcGet
(
SSLCursor
*
pSlc
,
const
void
**
ppKey
,
int32_t
*
nKey
,
const
void
**
ppData
,
int32_t
*
nData
);
int32_t
slcDrop
(
SSLCursor
*
pSlc
);
// struct
struct
SSLCfg
{
int8_t
maxLevel
;
int32_t
nKey
;
int32_t
nData
;
tslCmprFn
cmprFn
;
void
*
pPool
;
void
*
(
*
xMalloc
)(
void
*
,
int32_t
size
);
void
(
*
xFree
)(
void
*
,
void
*
);
};
#ifdef __cplusplus
}
#endif
#endif
/*_TD_UTIL_SKIPLIST2_H_*/
#if 0
#ifndef _TD_UTIL_SKILIST_H
#define _TD_UTIL_SKILIST_H
#include "os.h"
#include "taos.h"
#include "tarray.h"
#include "tfunctional.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_SKIP_LIST_LEVEL 15
#define SKIP_LIST_RECORD_PERFORMANCE 0
// For key property setting
#define SL_ALLOW_DUP_KEY (uint8_t)0x0 // Allow duplicate key exists (for tag index usage)
#define SL_DISCARD_DUP_KEY (uint8_t)0x1 // Discard duplicate key (for data update=0 case)
#define SL_UPDATE_DUP_KEY (uint8_t)0x2 // Update duplicate key by remove/insert (for data update!=0 case)
// For thread safety setting
#define SL_THREAD_SAFE (uint8_t)0x4
typedef char *SSkipListKey;
typedef char *(*__sl_key_fn_t)(const void *);
typedef void (*sl_patch_row_fn_t)(void *pDst, const void *pSrc);
typedef void *(*iter_next_fn_t)(void *iter);
typedef struct SSkipListNode {
uint8_t level;
void *pData;
struct SSkipListNode *forwards[];
} SSkipListNode;
#define SL_GET_NODE_DATA(n) (n)->pData
#define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)]
#define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)]
typedef enum { SSkipListPutSuccess = 0, SSkipListPutEarlyStop = 1, SSkipListPutSkipOne = 2 } SSkipListPutStatus;
typedef struct SSkipList {
uint32_t seed;
__compar_fn_t comparFn;
__sl_key_fn_t keyFn;
TdThreadRwlock *lock;
uint16_t len;
uint8_t maxLevel;
uint8_t flags;
uint8_t type; // static info above
uint8_t level;
uint32_t size;
SSkipListNode *pHead; // point to the first element
SSkipListNode *pTail; // point to the last element
tGenericSavedFunc *insertHandleFn;
} SSkipList;
typedef struct SSkipListIterator {
SSkipList *pSkipList;
SSkipListNode *cur;
int32_t step; // the number of nodes that have been checked already
int32_t order; // order of the iterator
SSkipListNode *next; // next points to the true qualified node in skiplist
} SSkipListIterator;
#define SL_IS_THREAD_SAFE(s) (((s)->flags) & SL_THREAD_SAFE)
#define SL_DUP_MODE(s) (((s)->flags) & ((((uint8_t)1) << 2) - 1))
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn((n)->pData))
#define SL_GET_MIN_KEY(s) SL_GET_NODE_KEY(s, SL_NODE_GET_FORWARD_POINTER((s)->pHead, 0))
#define SL_GET_MAX_KEY(s) SL_GET_NODE_KEY((s), SL_NODE_GET_BACKWARD_POINTER((s)->pTail, 0))
#define SL_SIZE(s) (s)->size
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
__sl_key_fn_t fn);
void tSkipListDestroy(SSkipList *pSkipList);
SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData);
void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t iterate);
SArray *tSkipListGet(SSkipList *pSkipList, SSkipListKey pKey);
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel);
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList);
SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order);
bool tSkipListIterNext(SSkipListIterator *iter);
SSkipListNode *tSkipListIterGet(SSkipListIterator *iter);
void *tSkipListDestroyIter(SSkipListIterator *iter);
uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key);
void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode);
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_SKILIST_H*/
#endif
\ No newline at end of file
source/libs/tdb/test/tdbTest.cpp
浏览文件 @
05f06e04
...
...
@@ -316,4 +316,6 @@ TEST(tdb_test, simple_test2) {
// Close Env
ret
=
tdbEnvClose
(
pEnv
);
GTEST_ASSERT_EQ
(
ret
,
0
);
}
\ No newline at end of file
}
TEST
(
tdb_test
,
simple_delete1
)
{
taosRemoveDir
(
"tdb"
);
}
\ No newline at end of file
source/util/src/tskiplist2.c
0 → 100644
浏览文件 @
05f06e04
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* 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/>.
*/
#include "tskiplist2.h"
typedef
struct
SSLNode
SSLNode
;
struct
SSLNode
{
int8_t
level
;
SSLNode
*
forwards
[];
};
struct
SSkipList2
{
int8_t
level
;
uint32_t
seed
;
int32_t
size
;
const
SSLCfg
*
pCfg
;
};
struct
SSLCursor
{
SSkipList2
*
pSl
;
SSLNode
*
forwards
[
SL_MAX_LEVEL
];
};
static
void
*
slMalloc
(
void
*
pPool
,
int32_t
size
);
static
void
slFree
(
void
*
pPool
,
void
*
p
);
static
int32_t
slCmprFn
(
const
void
*
pKey
,
int32_t
nKey
,
const
void
*
pData
,
int32_t
nData
);
const
SSLCfg
slDefaultCfg
=
{.
maxLevel
=
SL_MAX_LEVEL
,
.
nKey
=
-
1
,
.
nData
=
-
1
,
.
cmprFn
=
slCmprFn
,
.
pPool
=
NULL
,
.
xMalloc
=
slMalloc
,
.
xFree
=
slFree
};
int32_t
slOpen
(
const
SSLCfg
*
pCfg
,
SSkipList2
**
ppSl
)
{
SSkipList2
*
pSl
=
NULL
;
*
ppSl
=
NULL
;
if
(
pCfg
==
NULL
)
pCfg
=
&
slDefaultCfg
;
// check cfg (TODO)
// create handle
pSl
=
pCfg
->
xMalloc
(
pCfg
->
pPool
,
sizeof
(
*
pSl
));
// (TODO)
*
ppSl
=
pSl
;
return
0
;
}
int32_t
slClose
(
SSkipList2
*
pSl
)
{
// TODO
return
0
;
}
int32_t
slcOpen
(
SSkipList2
*
pSl
,
SSLCursor
*
pSlc
)
{
// TODO
return
0
;
}
int32_t
slcClose
(
SSLCursor
*
pSlc
)
{
// TODO
return
0
;
}
int32_t
slcMoveTo
(
SSLCursor
*
pSlc
,
const
void
*
pKey
,
int32_t
nKey
)
{
// TODO
return
0
;
}
int32_t
slcMoveToNext
(
SSLCursor
*
pSlc
)
{
// TODO
return
0
;
}
int32_t
slcMoveToPrev
(
SSLCursor
*
pSlc
)
{
// TODO
return
0
;
}
int32_t
slcMoveToFirst
(
SSLCursor
*
pSlc
)
{
// TODO
return
0
;
}
int32_t
slcMoveToLast
(
SSLCursor
*
pSlc
)
{
// TODO
return
0
;
}
int32_t
slcPut
(
SSLCursor
*
pSlc
,
const
void
*
pKey
,
int32_t
nKey
,
const
void
*
pData
,
int32_t
nData
)
{
// TODO
return
0
;
}
int32_t
slcGet
(
SSLCursor
*
pSlc
,
const
void
**
ppKey
,
int32_t
*
nKey
,
const
void
**
ppData
,
int32_t
*
nData
)
{
// TODO
return
0
;
}
int32_t
slcDrop
(
SSLCursor
*
pSlc
)
{
// TODO
return
0
;
}
static
FORCE_INLINE
void
*
slMalloc
(
void
*
pPool
,
int32_t
size
)
{
return
taosMemoryMalloc
(
size
);
}
static
FORCE_INLINE
void
slFree
(
void
*
pPool
,
void
*
p
)
{
taosMemoryFree
(
p
);
}
static
int32_t
slCmprFn
(
const
void
*
pKey1
,
int32_t
nKey1
,
const
void
*
pKey2
,
int32_t
nKey2
)
{
ASSERT
(
nKey1
>=
0
&&
nKey2
>=
0
);
int32_t
nKey
=
nKey1
>
nKey2
?
nKey2
:
nKey1
;
int32_t
c
;
c
=
memcmp
(
pKey1
,
pKey2
,
nKey
);
if
(
c
==
0
)
{
if
(
nKey1
>
nKey2
)
{
c
=
1
;
}
else
if
(
nKey1
<
nKey2
)
{
c
=
-
1
;
}
}
return
c
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录