more sl refact
This commit is contained in:
parent
d3487c88c2
commit
cfada1cc8a
|
@ -32,6 +32,7 @@ typedef int32_t (*tslCmprFn)(const void *pKey1, int32_t nKey1, const void *pKey2
|
||||||
// SSkipList2
|
// SSkipList2
|
||||||
int32_t slOpen(const SSLCfg *pCfg, SSkipList2 **ppSl);
|
int32_t slOpen(const SSLCfg *pCfg, SSkipList2 **ppSl);
|
||||||
int32_t slClose(SSkipList2 *pSl);
|
int32_t slClose(SSkipList2 *pSl);
|
||||||
|
int32_t slClear(SSkipList2 *pSl);
|
||||||
|
|
||||||
// SSLCursor
|
// SSLCursor
|
||||||
int32_t slcOpen(SSkipList2 *pSl, SSLCursor *pSlc);
|
int32_t slcOpen(SSkipList2 *pSl, SSLCursor *pSlc);
|
||||||
|
@ -56,6 +57,11 @@ struct SSLCfg {
|
||||||
void (*xFree)(void *, void *);
|
void (*xFree)(void *, void *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SSLCursor {
|
||||||
|
SSkipList2 *pSl;
|
||||||
|
SSLNode **forwards[SL_MAX_LEVEL];
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,11 +27,7 @@ struct SSkipList2 {
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
int32_t size;
|
int32_t size;
|
||||||
const SSLCfg *pCfg;
|
const SSLCfg *pCfg;
|
||||||
};
|
SSLNode *pHead[];
|
||||||
|
|
||||||
struct SSLCursor {
|
|
||||||
SSkipList2 *pSl;
|
|
||||||
SSLNode *forwards[SL_MAX_LEVEL];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *slMalloc(void *pPool, int32_t size);
|
static void *slMalloc(void *pPool, int32_t size);
|
||||||
|
@ -48,25 +44,66 @@ const SSLCfg slDefaultCfg = {.maxLevel = SL_MAX_LEVEL,
|
||||||
|
|
||||||
int32_t slOpen(const SSLCfg *pCfg, SSkipList2 **ppSl) {
|
int32_t slOpen(const SSLCfg *pCfg, SSkipList2 **ppSl) {
|
||||||
SSkipList2 *pSl = NULL;
|
SSkipList2 *pSl = NULL;
|
||||||
|
int32_t size;
|
||||||
|
|
||||||
*ppSl = NULL;
|
*ppSl = NULL;
|
||||||
if (pCfg == NULL) pCfg = &slDefaultCfg;
|
if (pCfg == NULL) pCfg = &slDefaultCfg;
|
||||||
|
|
||||||
// check cfg (TODO)
|
// check config (TODO)
|
||||||
|
|
||||||
|
// malloc handle
|
||||||
|
size = sizeof(*pSl) + sizeof(SSLNode *) * pCfg->maxLevel * 2;
|
||||||
|
pSl = pCfg->xMalloc(pCfg->pPool, size);
|
||||||
|
if (pSl == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pSl->level = 0;
|
||||||
|
pSl->seed = taosRand();
|
||||||
|
pSl->size = 0;
|
||||||
|
pSl->pCfg = pCfg;
|
||||||
|
|
||||||
|
// init an empty skiplist
|
||||||
|
for (int32_t i = 0; i < pCfg->maxLevel * 2; i++) {
|
||||||
|
pSl->pHead[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// create handle
|
|
||||||
pSl = pCfg->xMalloc(pCfg->pPool, sizeof(*pSl));
|
|
||||||
// (TODO)
|
|
||||||
*ppSl = pSl;
|
*ppSl = pSl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t slClose(SSkipList2 *pSl) {
|
int32_t slClose(SSkipList2 *pSl) {
|
||||||
// TODO
|
if (pSl) {
|
||||||
|
slClear(pSl);
|
||||||
|
if (pSl->pCfg->xFree) {
|
||||||
|
pSl->pCfg->xFree(pSl->pCfg->pPool, pSl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t slClear(SSkipList2 *pSl) {
|
||||||
|
// loop to clear sl
|
||||||
|
for (;;) {
|
||||||
|
// (TODO)
|
||||||
|
}
|
||||||
|
|
||||||
|
// init sl (TODO)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t slcOpen(SSkipList2 *pSl, SSLCursor *pSlc) {
|
int32_t slcOpen(SSkipList2 *pSl, SSLCursor *pSlc) {
|
||||||
|
pSlc->pSl = pSl;
|
||||||
|
|
||||||
|
for (int i = 0; i < SL_MAX_LEVEL; i++) {
|
||||||
|
if (i < pSl->pCfg->maxLevel) {
|
||||||
|
} else {
|
||||||
|
pSlc->forwards[i] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue