提交 e591a3eb 编写于 作者: H hjxilinx

[td-98] optimize put performance by comparing the minimum key of skip list...

[td-98] optimize put performance by comparing the minimum key of skip list before starting to find the appropriated position in the list.
上级 3a3ccf40
......@@ -50,6 +50,8 @@ typedef struct SSkipListNode {
#define SL_GET_NODE_DATA(n) ((char *)(n) + SL_NODE_HEADER_SIZE((n)->level))
#define SL_GET_NODE_KEY(s, n) ((s)->keyFn(SL_GET_NODE_DATA(n)))
#define SL_GET_SL_MIN_KEY(s) (SL_GET_NODE_KEY((s), SL_GET_FORWARD_POINTER((s)->pHead, 0)))
#define SL_GET_NODE_LEVEL(n) *(uint8_t *)((n))
/*
......
......@@ -71,7 +71,8 @@ memset(pNode, 0, SL_NODE_HEADER_SIZE(_l));\
} while(0)
static void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **forward, SSkipListNode *pNode);
static SSkipListNode* tSkipListDoAppend(SSkipList *pSkipList, SSkipListNode *pNode);
static SSkipListNode* tSkipListPushBack(SSkipList *pSkipList, SSkipListNode *pNode);
static SSkipListNode* tSkipListPushFront(SSkipList* pSkipList, SSkipListNode *pNode);
static SSkipListIterator* doCreateSkipListIterator(SSkipList *pSkipList, int32_t order);
static bool initForwardBackwardPtr(SSkipList* pSkipList) {
......@@ -207,10 +208,17 @@ SSkipListNode *tSkipListPut(SSkipList *pSkipList, SSkipListNode *pNode) {
pthread_rwlock_wrlock(pSkipList->lock);
}
// the new key is greater than the last key of skiplist append it at last position
// if the new key is greater than the maximum key of skip list, push back this node at the end of skip list
char *newDatakey = SL_GET_NODE_KEY(pSkipList, pNode);
if (pSkipList->size == 0 || pSkipList->comparFn(pSkipList->lastKey, newDatakey) < 0) {
return tSkipListDoAppend(pSkipList, pNode);
return tSkipListPushBack(pSkipList, pNode);
}
// if the new key is less than the minimum key of skip list, push front this node at the front of skip list
assert(pSkipList->size > 0);
char* minKey = SL_GET_SL_MIN_KEY(pSkipList);
if (pSkipList->comparFn(newDatakey, minKey) < 0) {
return tSkipListPushFront(pSkipList, pNode);
}
// find the appropriated position to insert data
......@@ -269,7 +277,17 @@ void tSkipListDoInsert(SSkipList *pSkipList, SSkipListNode **forward, SSkipListN
}
}
SSkipListNode* tSkipListDoAppend(SSkipList *pSkipList, SSkipListNode *pNode) {
SSkipListNode* tSkipListPushFront(SSkipList* pSkipList, SSkipListNode *pNode) {
SSkipListNode* forward[MAX_SKIP_LIST_LEVEL] = {0};
for(int32_t i = 0; i < pSkipList->level; ++i) {
forward[i] = pSkipList->pHead;
}
tSkipListDoInsert(pSkipList, forward, pNode);
return pNode;
}
SSkipListNode* tSkipListPushBack(SSkipList *pSkipList, SSkipListNode *pNode) {
// do clear pointer area
DO_MEMSET_PTR_AREA(pNode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册