add test case
This commit is contained in:
parent
ffedfbaf1e
commit
db03fbd896
|
@ -21,7 +21,7 @@
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
static int32_t initForwardBackwardPtr(SSkipList *pSkipList);
|
static int32_t initForwardBackwardPtr(SSkipList *pSkipList);
|
||||||
static SSkipListNode *getPriorNode(SSkipList *pSkipList, const char *val, int32_t order, SSkipListNode **pCur);
|
static SSkipListNode * getPriorNode(SSkipList *pSkipList, const char *val, int32_t order, SSkipListNode **pCur);
|
||||||
static void tSkipListRemoveNodeImpl(SSkipList *pSkipList, SSkipListNode *pNode);
|
static void tSkipListRemoveNodeImpl(SSkipList *pSkipList, SSkipListNode *pNode);
|
||||||
static void tSkipListCorrectLevel(SSkipList *pSkipList);
|
static void tSkipListCorrectLevel(SSkipList *pSkipList);
|
||||||
static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t order);
|
static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t order);
|
||||||
|
@ -131,12 +131,14 @@ SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData) {
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_NO_CALL
|
||||||
|
|
||||||
void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t iterate) {
|
void tSkipListPutBatchByIter(SSkipList *pSkipList, void *iter, iter_next_fn_t iterate) {
|
||||||
SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0};
|
SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0};
|
||||||
SSkipListNode *forward[MAX_SKIP_LIST_LEVEL] = {0};
|
SSkipListNode *forward[MAX_SKIP_LIST_LEVEL] = {0};
|
||||||
bool hasDup = false;
|
bool hasDup = false;
|
||||||
char *pKey = NULL;
|
char * pKey = NULL;
|
||||||
char *pDataKey = NULL;
|
char * pDataKey = NULL;
|
||||||
int32_t compare = 0;
|
int32_t compare = 0;
|
||||||
|
|
||||||
tSkipListWLock(pSkipList);
|
tSkipListWLock(pSkipList);
|
||||||
|
@ -260,6 +262,7 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode) {
|
||||||
tSkipListCorrectLevel(pSkipList);
|
tSkipListCorrectLevel(pSkipList);
|
||||||
tSkipListUnlock(pSkipList);
|
tSkipListUnlock(pSkipList);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList) {
|
SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList) {
|
||||||
if (pSkipList == NULL) return NULL;
|
if (pSkipList == NULL) return NULL;
|
||||||
|
@ -350,6 +353,7 @@ void *tSkipListDestroyIter(SSkipListIterator *iter) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_NO_CALL
|
||||||
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel) {
|
void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel) {
|
||||||
if (pSkipList == NULL || pSkipList->level < nlevel || nlevel <= 0) {
|
if (pSkipList == NULL || pSkipList->level < nlevel || nlevel <= 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -358,7 +362,7 @@ void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel) {
|
||||||
SSkipListNode *p = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, nlevel - 1);
|
SSkipListNode *p = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, nlevel - 1);
|
||||||
|
|
||||||
int32_t id = 1;
|
int32_t id = 1;
|
||||||
char *prev = NULL;
|
char * prev = NULL;
|
||||||
|
|
||||||
while (p != pSkipList->pTail) {
|
while (p != pSkipList->pTail) {
|
||||||
char *key = SL_GET_NODE_KEY(pSkipList, p);
|
char *key = SL_GET_NODE_KEY(pSkipList, p);
|
||||||
|
@ -392,6 +396,7 @@ void tSkipListPrint(SSkipList *pSkipList, int16_t nlevel) {
|
||||||
p = SL_NODE_GET_FORWARD_POINTER(p, nlevel - 1);
|
p = SL_NODE_GET_FORWARD_POINTER(p, nlevel - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **direction, SSkipListNode *pNode, bool isForward) {
|
static void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **direction, SSkipListNode *pNode, bool isForward) {
|
||||||
for (int32_t i = 0; i < pNode->level; ++i) {
|
for (int32_t i = 0; i < pNode->level; ++i) {
|
||||||
|
@ -460,7 +465,7 @@ static FORCE_INLINE int32_t tSkipListUnlock(SSkipList *pSkipList) {
|
||||||
static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward, void *pData) {
|
static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward, void *pData) {
|
||||||
int32_t compare = 0;
|
int32_t compare = 0;
|
||||||
bool hasDupKey = false;
|
bool hasDupKey = false;
|
||||||
char *pDataKey = pSkipList->keyFn(pData);
|
char * pDataKey = pSkipList->keyFn(pData);
|
||||||
|
|
||||||
if (pSkipList->size == 0) {
|
if (pSkipList->size == 0) {
|
||||||
for (int32_t i = 0; i < pSkipList->maxLevel; i++) {
|
for (int32_t i = 0; i < pSkipList->maxLevel; i++) {
|
||||||
|
@ -516,6 +521,7 @@ static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward,
|
||||||
return hasDupKey;
|
return hasDupKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_NO_CALL
|
||||||
static void tSkipListRemoveNodeImpl(SSkipList *pSkipList, SSkipListNode *pNode) {
|
static void tSkipListRemoveNodeImpl(SSkipList *pSkipList, SSkipListNode *pNode) {
|
||||||
int32_t level = pNode->level;
|
int32_t level = pNode->level;
|
||||||
uint8_t dupMode = SL_DUP_MODE(pSkipList);
|
uint8_t dupMode = SL_DUP_MODE(pSkipList);
|
||||||
|
@ -540,6 +546,7 @@ static void tSkipListCorrectLevel(SSkipList *pSkipList) {
|
||||||
pSkipList->level -= 1;
|
pSkipList->level -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
UNUSED_FUNC static FORCE_INLINE void recordNodeEachLevel(SSkipList *pSkipList,
|
UNUSED_FUNC static FORCE_INLINE void recordNodeEachLevel(SSkipList *pSkipList,
|
||||||
int32_t level) { // record link count in each level
|
int32_t level) { // record link count in each level
|
||||||
|
|
Loading…
Reference in New Issue