提交 9d5e0d53 编写于 作者: H Hongze Cheng

refactor list

上级 50749639
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
extern "C" { extern "C" {
#endif #endif
// Single linked list // Single linked list ================
#define TD_SLIST_NODE(TYPE) \ #define TD_SLIST_NODE(TYPE) \
struct { \ struct { \
struct TYPE *sl_next_; \ struct TYPE *sl_next_; \
...@@ -35,30 +35,30 @@ extern "C" { ...@@ -35,30 +35,30 @@ extern "C" {
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_) #define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_) #define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define tSListInit(sl) \ #define TD_SLIST_INIT(sl) \
do { \ do { \
(sl)->sl_head_ = NULL; \ (sl)->sl_head_ = NULL; \
(sl)->sl_neles_ = 0; \ (sl)->sl_neles_ = 0; \
} while (0) } while (0)
#define tSListPush(sl, sln) \ #define TD_SLIST_PUSH(sl, sln) \
do { \ do { \
TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \ TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \
TD_SLIST_HEAD(sl) = (sln); \ TD_SLIST_HEAD(sl) = (sln); \
TD_SLIST_NELES(sl) += 1; \ TD_SLIST_NELES(sl) += 1; \
} while (0) } while (0)
#define tSListPop(sl) \ #define TD_SLIST_POP(sl) \
do { \ do { \
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \ TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
TD_SLIST_NELES(sl) -= 1; \ TD_SLIST_NELES(sl) -= 1; \
} while (0) } while (0)
// Double linked list // Double linked list ================
#define TD_DLIST_NODE(TYPE) \ #define TD_DLIST_NODE(TYPE) \
struct { \ struct { \
struct TYPE *dl_prev_; \ struct TYPE *dl_prev_; \
struct TYPE *dl_next_; \ struct TYPE *dl_next_; \
} }
#define TD_DLIST(TYPE) \ #define TD_DLIST(TYPE) \
...@@ -74,13 +74,13 @@ extern "C" { ...@@ -74,13 +74,13 @@ extern "C" {
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_) #define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_) #define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define tDListInit(dl) \ #define TD_DLIST_INIT(dl) \
do { \ do { \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \ TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
TD_DLIST_NELES(dl) = 0; \ TD_DLIST_NELES(dl) = 0; \
} while (0) } while (0)
#define tDListAppend(dl, dln) \ #define TD_DLIST_APPEND(dl, dln) \
do { \ do { \
if (TD_DLIST_HEAD(dl) == NULL) { \ if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
...@@ -94,7 +94,7 @@ extern "C" { ...@@ -94,7 +94,7 @@ extern "C" {
TD_DLIST_NELES(dl) += 1; \ TD_DLIST_NELES(dl) += 1; \
} while (0) } while (0)
#define tDListPrepend(dl, dln) \ #define TD_DLIST_PREPEND(dl, dln) \
do { \ do { \
if (TD_DLIST_HEAD(dl) == NULL) { \ if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
...@@ -108,7 +108,7 @@ extern "C" { ...@@ -108,7 +108,7 @@ extern "C" {
TD_DLIST_NELES(dl) += 1; \ TD_DLIST_NELES(dl) += 1; \
} while (0) } while (0)
#define tDListPop(dl, dln) \ #define TD_DLIST_POP(dl, dln) \
do { \ do { \
if (TD_DLIST_HEAD(dl) == (dln)) { \ if (TD_DLIST_HEAD(dl) == (dln)) { \
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \ TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \
...@@ -126,19 +126,17 @@ extern "C" { ...@@ -126,19 +126,17 @@ extern "C" {
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \ TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
} while (0) } while (0)
// General double linked list
typedef enum { TD_LIST_FORWARD, TD_LIST_BACKWARD } TD_LIST_DIRECTION_T; typedef enum { TD_LIST_FORWARD, TD_LIST_BACKWARD } TD_LIST_DIRECTION_T;
typedef struct _list_node { typedef struct SListNode {
struct _list_node *next; TD_DLIST_NODE(SListNode);
struct _list_node *prev; char data[];
char data[];
} SListNode; } SListNode;
typedef struct { typedef struct {
struct _list_node *head; TD_DLIST(SListNode);
struct _list_node *tail; int eleSize;
int numOfEles;
int eleSize;
} SList; } SList;
typedef struct { typedef struct {
...@@ -146,11 +144,11 @@ typedef struct { ...@@ -146,11 +144,11 @@ typedef struct {
TD_LIST_DIRECTION_T direction; TD_LIST_DIRECTION_T direction;
} SListIter; } SListIter;
#define listHead(l) (l)->head #define listHead(l) TD_DLIST_HEAD(l)
#define listTail(l) (l)->tail #define listTail(l) TD_DLIST_TAIL(l)
#define listNEles(l) (l)->numOfEles #define listNEles(l) TD_DLIST_NELES(l)
#define listEleSize(l) (l)->eleSize #define listEleSize(l) ((l)->eleSize)
#define isListEmpty(l) ((l)->numOfEles == 0) #define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
#define listNodeFree(n) free(n) #define listNodeFree(n) free(n)
void tdListInit(SList *list, int eleSize); void tdListInit(SList *list, int eleSize);
......
...@@ -27,7 +27,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { ...@@ -27,7 +27,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
pVMA->capacity = capacity; pVMA->capacity = capacity;
pVMA->ssize = ssize; pVMA->ssize = ssize;
pVMA->lsize = lsize; pVMA->lsize = lsize;
tSListInit(&(pVMA->nlist)); TD_SLIST_INIT(&(pVMA->nlist));
pVMA->pNode = vArenaNodeNew(capacity); pVMA->pNode = vArenaNodeNew(capacity);
if (pVMA->pNode == NULL) { if (pVMA->pNode == NULL) {
...@@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { ...@@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
return NULL; return NULL;
} }
tSListPush(&(pVMA->nlist), pVMA->pNode); TD_SLIST_PUSH(&(pVMA->nlist), pVMA->pNode);
return pVMA; return pVMA;
} }
...@@ -44,7 +44,7 @@ void vmaDestroy(SVMemAllocator *pVMA) { ...@@ -44,7 +44,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
if (pVMA) { if (pVMA) {
while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) { while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) {
SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist)); SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist));
tSListPop(&(pVMA->nlist)); TD_SLIST_POP(&(pVMA->nlist));
vArenaNodeFree(pNode); vArenaNodeFree(pNode);
} }
...@@ -55,7 +55,7 @@ void vmaDestroy(SVMemAllocator *pVMA) { ...@@ -55,7 +55,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
void vmaReset(SVMemAllocator *pVMA) { void vmaReset(SVMemAllocator *pVMA) {
while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) { while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) {
SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist)); SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist));
tSListPop(&(pVMA->nlist)); TD_SLIST_POP(&(pVMA->nlist));
vArenaNodeFree(pNode); vArenaNodeFree(pNode);
} }
...@@ -75,7 +75,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) { ...@@ -75,7 +75,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) {
return NULL; return NULL;
} }
tSListPush(&(pVMA->nlist), pNode); TD_SLIST_PUSH(&(pVMA->nlist), pNode);
} }
ptr = pNode->ptr; ptr = pNode->ptr;
......
...@@ -39,8 +39,8 @@ int vnodeOpenBufPool(SVnode *pVnode) { ...@@ -39,8 +39,8 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return -1; return -1;
} }
tDListInit(&(pVnode->pBufPool->free)); TD_DLIST_INIT(&(pVnode->pBufPool->free));
tDListInit(&(pVnode->pBufPool->incycle)); TD_DLIST_INIT(&(pVnode->pBufPool->incycle));
pVnode->pBufPool->inuse = NULL; pVnode->pBufPool->inuse = NULL;
...@@ -54,7 +54,7 @@ int vnodeOpenBufPool(SVnode *pVnode) { ...@@ -54,7 +54,7 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return -1; return -1;
} }
tDListAppend(&(pVnode->pBufPool->free), pVMA); TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA);
} }
pVnode->pBufPool->pMAF = (SMemAllocatorFactory *)malloc(sizeof(SMemAllocatorFactory)); pVnode->pBufPool->pMAF = (SMemAllocatorFactory *)malloc(sizeof(SMemAllocatorFactory));
...@@ -76,14 +76,14 @@ void vnodeCloseBufPool(SVnode *pVnode) { ...@@ -76,14 +76,14 @@ void vnodeCloseBufPool(SVnode *pVnode) {
while (true) { while (true) {
SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->incycle)); SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->incycle));
if (pVMA == NULL) break; if (pVMA == NULL) break;
tDListPop(&(pVnode->pBufPool->incycle), pVMA); TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA);
vmaDestroy(pVMA); vmaDestroy(pVMA);
} }
while (true) { while (true) {
SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->free)); SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->free));
if (pVMA == NULL) break; if (pVMA == NULL) break;
tDListPop(&(pVnode->pBufPool->free), pVMA); TD_DLIST_POP(&(pVnode->pBufPool->free), pVMA);
vmaDestroy(pVMA); vmaDestroy(pVMA);
} }
...@@ -97,7 +97,7 @@ int vnodeBufPoolSwitch(SVnode *pVnode) { ...@@ -97,7 +97,7 @@ int vnodeBufPoolSwitch(SVnode *pVnode) {
pVnode->pBufPool->inuse = NULL; pVnode->pBufPool->inuse = NULL;
tDListAppend(&(pVnode->pBufPool->incycle), pvma); TD_DLIST_APPEND(&(pVnode->pBufPool->incycle), pvma);
return 0; return 0;
} }
...@@ -106,9 +106,9 @@ int vnodeBufPoolRecycle(SVnode *pVnode) { ...@@ -106,9 +106,9 @@ int vnodeBufPoolRecycle(SVnode *pVnode) {
SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle)); SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle));
ASSERT(pvma != NULL); ASSERT(pvma != NULL);
tDListPop(&(pBufPool->incycle), pvma); TD_DLIST_POP(&(pBufPool->incycle), pvma);
vmaReset(pvma); vmaReset(pvma);
tDListAppend(&(pBufPool->free), pvma); TD_DLIST_APPEND(&(pBufPool->free), pvma);
return 0; return 0;
} }
...@@ -121,7 +121,7 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) { ...@@ -121,7 +121,7 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
// TODO: add sem_wait and sem_post // TODO: add sem_wait and sem_post
pBufPool->inuse = TD_DLIST_HEAD(&(pBufPool->free)); pBufPool->inuse = TD_DLIST_HEAD(&(pBufPool->free));
if (pBufPool->inuse) { if (pBufPool->inuse) {
tDListPop(&(pBufPool->free), pBufPool->inuse); TD_DLIST_POP(&(pBufPool->free), pBufPool->inuse);
break; break;
} else { } else {
// tsem_wait(&(pBufPool->hasFree)); // tsem_wait(&(pBufPool->hasFree));
...@@ -184,7 +184,7 @@ static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA) { ...@@ -184,7 +184,7 @@ static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA) {
free(pMA); free(pMA);
if (--pVMA->_ref.val == 0) { if (--pVMA->_ref.val == 0) {
tDListPop(&(pVnode->pBufPool->incycle), pVMA); TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA);
tDListAppend(&(pVnode->pBufPool->free), pVMA); TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA);
} }
} }
\ No newline at end of file
...@@ -34,7 +34,7 @@ int vnodeInit(uint16_t nthreads) { ...@@ -34,7 +34,7 @@ int vnodeInit(uint16_t nthreads) {
pthread_mutex_init(&(vnodeMgr.mutex), NULL); pthread_mutex_init(&(vnodeMgr.mutex), NULL);
pthread_cond_init(&(vnodeMgr.hasTask), NULL); pthread_cond_init(&(vnodeMgr.hasTask), NULL);
tDListInit(&(vnodeMgr.queue)); TD_DLIST_INIT(&(vnodeMgr.queue));
for (uint16_t i = 0; i < nthreads; i++) { for (uint16_t i = 0; i < nthreads; i++) {
pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL); pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL);
...@@ -77,7 +77,7 @@ void vnodeClear() { ...@@ -77,7 +77,7 @@ void vnodeClear() {
int vnodeScheduleTask(SVnodeTask* pTask) { int vnodeScheduleTask(SVnodeTask* pTask) {
pthread_mutex_lock(&(vnodeMgr.mutex)); pthread_mutex_lock(&(vnodeMgr.mutex));
tDListAppend(&(vnodeMgr.queue), pTask); TD_DLIST_APPEND(&(vnodeMgr.queue), pTask);
pthread_cond_signal(&(vnodeMgr.hasTask)); pthread_cond_signal(&(vnodeMgr.hasTask));
...@@ -101,7 +101,7 @@ static void* loop(void* arg) { ...@@ -101,7 +101,7 @@ static void* loop(void* arg) {
pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex)); pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex));
} }
} else { } else {
tDListPop(&(vnodeMgr.queue), pTask); TD_DLIST_POP(&(vnodeMgr.queue), pTask);
break; break;
} }
} }
......
...@@ -62,7 +62,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) { ...@@ -62,7 +62,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
pMemTable->keyMax = TSKEY_MIN; pMemTable->keyMax = TSKEY_MIN;
pMemTable->nRow = 0; pMemTable->nRow = 0;
pMemTable->pMA = pMA; pMemTable->pMA = pMA;
tSListInit(&(pMemTable->list)); TD_SLIST_INIT(&(pMemTable->list));
// TODO // TODO
return pMemTable; return pMemTable;
...@@ -86,7 +86,7 @@ int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) { ...@@ -86,7 +86,7 @@ int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) {
// TODO // TODO
} }
tSListPush(&(pMemTable->list), pTbData); TD_SLIST_PUSH(&(pMemTable->list), pTbData);
return 0; return 0;
} }
......
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
#include "os.h" #include "os.h"
void tdListInit(SList *list, int eleSize) { void tdListInit(SList *list, int eleSize) {
list->eleSize = eleSize; TD_DLIST_INIT(list);
list->numOfEles = 0; listEleSize(list) = eleSize;
list->head = list->tail = NULL;
} }
SList *tdListNew(int eleSize) { SList *tdListNew(int eleSize) {
...@@ -31,14 +30,11 @@ SList *tdListNew(int eleSize) { ...@@ -31,14 +30,11 @@ SList *tdListNew(int eleSize) {
} }
void tdListEmpty(SList *list) { void tdListEmpty(SList *list) {
SListNode *node = list->head; SListNode *node;
while (node) { while ((node = TD_DLIST_HEAD(list)) != NULL) {
list->head = node->next; TD_DLIST_POP(list, node);
free(node); free(node);
node = list->head;
} }
list->head = list->tail = 0;
list->numOfEles = 0;
} }
void *tdListFree(SList *list) { void *tdListFree(SList *list) {
...@@ -50,40 +46,16 @@ void *tdListFree(SList *list) { ...@@ -50,40 +46,16 @@ void *tdListFree(SList *list) {
return NULL; return NULL;
} }
void tdListPrependNode(SList *list, SListNode *node) { void tdListPrependNode(SList *list, SListNode *node) { TD_DLIST_PREPEND(list, node); }
if (list->head == NULL) {
list->head = node;
list->tail = node;
} else {
node->next = list->head;
node->prev = NULL;
list->head->prev = node;
list->head = node;
}
list->numOfEles++;
}
void tdListAppendNode(SList *list, SListNode *node) {
if (list->head == NULL) {
list->head = node;
list->tail = node;
} else {
node->prev = list->tail;
node->next = NULL;
list->tail->next = node;
list->tail = node;
}
list->numOfEles++; void tdListAppendNode(SList *list, SListNode *node) { TD_DLIST_APPEND(list, node); }
}
int tdListPrepend(SList *list, void *data) { int tdListPrepend(SList *list, void *data) {
SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize); SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize);
if (node == NULL) return -1; if (node == NULL) return -1;
node->next = node->prev = NULL;
memcpy((void *)(node->data), data, list->eleSize); memcpy((void *)(node->data), data, list->eleSize);
tdListPrependNode(list, node); TD_DLIST_PREPEND(list, node);
return 0; return 0;
} }
...@@ -93,73 +65,40 @@ int tdListAppend(SList *list, void *data) { ...@@ -93,73 +65,40 @@ int tdListAppend(SList *list, void *data) {
if (node == NULL) return -1; if (node == NULL) return -1;
memcpy((void *)(node->data), data, list->eleSize); memcpy((void *)(node->data), data, list->eleSize);
tdListAppendNode(list, node); TD_DLIST_APPEND(list, node);
return 0; return 0;
} }
SListNode *tdListPopHead(SList *list) { SListNode *tdListPopHead(SList *list) {
if (list->head == NULL) return NULL; SListNode *node;
SListNode *node = list->head;
if (node->next == NULL) { node = TD_DLIST_HEAD(list);
list->head = NULL;
list->tail = NULL; if (node) {
} else { TD_DLIST_POP(list, node);
list->head = node->next;
} }
list->numOfEles--;
node->next = NULL;
node->prev = NULL;
return node; return node;
} }
SListNode *tdListPopTail(SList *list) { SListNode *tdListPopTail(SList *list) {
if (list->tail == NULL) return NULL; SListNode *node;
SListNode *node = list->tail;
if (node->prev == NULL) {
list->head = NULL;
list->tail = NULL;
} else {
list->tail = node->prev;
}
list->numOfEles--;
node->next = node->prev = NULL;
return node;
}
SListNode *tdListGetHead(SList *list) { node = TD_DLIST_TAIL(list);
if (list == NULL || list->numOfEles == 0) { if (node) {
return NULL; TD_DLIST_POP(list, node);
} }
return list->head; return node;
} }
SListNode *tsListGetTail(SList *list) { SListNode *tdListGetHead(SList *list) { return TD_DLIST_HEAD(list); }
if (list == NULL || list->numOfEles == 0) {
return NULL;
}
return list->tail; SListNode *tsListGetTail(SList *list) { return TD_DLIST_TAIL(list); }
}
SListNode *tdListPopNode(SList *list, SListNode *node) { SListNode *tdListPopNode(SList *list, SListNode *node) {
if (list->head == node) { TD_DLIST_POP(list, node);
list->head = node->next;
}
if (list->tail == node) {
list->tail = node->prev;
}
if (node->prev != NULL) {
node->prev->next = node->next;
}
if (node->next != NULL) {
node->next->prev = node->prev;
}
list->numOfEles--;
node->next = node->prev = NULL;
return node; return node;
} }
...@@ -174,19 +113,19 @@ void tdListMove(SList *src, SList *dst) { ...@@ -174,19 +113,19 @@ void tdListMove(SList *src, SList *dst) {
void tdListDiscard(SList *list) { void tdListDiscard(SList *list) {
if (list) { if (list) {
list->head = list->tail = NULL; listHead(list) = listTail(list) = NULL;
list->numOfEles = 0; listNEles(list) = 0;
} }
} }
void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(target, node->data, list->eleSize); } void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(target, node->data, listEleSize(list)); }
void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction) { void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction) {
pIter->direction = direction; pIter->direction = direction;
if (direction == TD_LIST_FORWARD) { if (direction == TD_LIST_FORWARD) {
pIter->next = list->head; pIter->next = listHead(list);
} else { } else {
pIter->next = list->tail; pIter->next = listTail(list);
} }
} }
...@@ -194,9 +133,9 @@ SListNode *tdListNext(SListIter *pIter) { ...@@ -194,9 +133,9 @@ SListNode *tdListNext(SListIter *pIter) {
SListNode *node = pIter->next; SListNode *node = pIter->next;
if (node == NULL) return NULL; if (node == NULL) return NULL;
if (pIter->direction == TD_LIST_FORWARD) { if (pIter->direction == TD_LIST_FORWARD) {
pIter->next = node->next; pIter->next = TD_DLIST_NODE_NEXT(node);
} else { } else {
pIter->next = node->prev; pIter->next = TD_DLIST_NODE_PREV(node);
} }
return node; return node;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册