TD-34
This commit is contained in:
parent
4e2c124c01
commit
e865255b20
|
@ -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 {
|
||||||
} 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
|
||||||
|
@ -53,6 +59,8 @@ 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
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,3 +123,24 @@ SListNode *tdListPopNode(SList *list, SListNode *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); }
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue