提交 e865255b 编写于 作者: H hzcheng

TD-34

上级 4e2c124c
...@@ -19,6 +19,11 @@ ...@@ -19,6 +19,11 @@
extern "C" { extern "C" {
#endif #endif
typedef enum {
TD_LIST_FORWARD,
TD_LIST_BACKWARD
} TD_LIST_DIRECTION_T;
typedef struct _list_node { typedef struct _list_node {
struct _list_node *next; struct _list_node *next;
struct _list_node *prev; struct _list_node *prev;
...@@ -33,7 +38,8 @@ typedef struct { ...@@ -33,7 +38,8 @@ typedef struct {
} SList; } SList;
typedef struct { typedef struct {
SListNode *node; SListNode * next;
TD_LIST_DIRECTION_T direction;
} SListIter; } SListIter;
#define listHead(l) (l)->head #define listHead(l) (l)->head
...@@ -52,7 +58,9 @@ SListNode *tdListPopHead(SList *list); ...@@ -52,7 +58,9 @@ SListNode *tdListPopHead(SList *list);
SListNode *tdListPopTail(SList *list); SListNode *tdListPopTail(SList *list);
SListNode *tdListPopNode(SList *list, SListNode *node); SListNode *tdListPopNode(SList *list, SListNode *node);
void tdListNodeGetData(SList *list, SListNode *node, void *target); void tdListNodeGetData(SList *list, SListNode *node, void *target);
void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction);
SListNode *tdListNext(SListIter *pIter);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -122,4 +122,25 @@ SListNode *tdListPopNode(SList *list, SListNode *node) { ...@@ -122,4 +122,25 @@ SListNode *tdListPopNode(SList *list, SListNode *node) {
return node; return node;
} }
void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(node->data, target, list->eleSize); } void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(node->data, target, list->eleSize); }
\ No newline at end of file
void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction) {
pIter->direction = direction;
if (direction == TD_LIST_FORWARD) {
pIter->next = list->head;
} else {
pIter->next = list->tail;
}
}
SListNode *tdListNext(SListIter *pIter) {
SListNode *node = pIter->next;
if (node == NULL) return NULL;
if (pIter->direction == TD_LIST_FORWARD) {
pIter->next = node->next;
} else {
pIter->next = node->prev;
}
return node;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册