Files
vxWorks/h/sllLib.h
2025-08-20 18:25:46 +08:00

265 lines
8.7 KiB
C

/* sllLib.h - singly linked list library header */
/* Copyright 1984-2005 Wind River Systems, Inc. */
/*
modification history
--------------------
02c,19jan05,vvv moved some macros from osdep.h
02b,22sep92,rrr added support for c++
02a,04jul92,jcf cleaned up.
01f,26may92,rrr the tree shuffle
01e,04oct91,rrr passed through the ansification filter
-changed VOID to void
-changed copyright notice
01d,08apr91,jdi added NOMANUAL to prevent mangen.
01c,05oct90,shl added ANSI function prototypes.
added copyright notice.
01b,10aug90,dnw changed declaration of sllRemove() from STATUS to void.
01a,03jun89,jcf written.
*/
#ifndef __INCsllLibh
#define __INCsllLibh
#ifdef __cplusplus
extern "C" {
#endif
/* type definitions */
typedef struct slnode /* Node of a linked list. */
{
struct slnode *next; /* Points at the next node in the list */
} SL_NODE;
/* HIDDEN */
typedef struct /* Header for a linked list. */
{
SL_NODE *head; /* header of list */
SL_NODE *tail; /* tail of list */
} SL_LIST;
/* END_HIDDEN */
/*******************************************************************************
*
* SLL_INIT - initialize singly linked list head
*
* Initialize the specified list to an empty list.
*
* NOMANUAL
*/
#define SLL_INIT(list) \
{ \
((SL_LIST *)(list))->head = NULL; \
((SL_LIST *)(list))->tail = NULL; \
}
/*******************************************************************************
*
* SLL_PUT_AT_HEAD - add node to beginning of list
*
* This macro adds the specified node to the end of the specified list.
*
* NOMANUAL
*/
#define SLL_PUT_AT_HEAD(list, node) \
{ \
if ((((SL_NODE *)(node))->next = ((SL_LIST *)(list))->head) == NULL) \
{ \
((SL_LIST *)(list))->head = ((SL_NODE *)(node)); \
((SL_LIST *)(list))->tail = ((SL_NODE *)(node)); \
} \
else \
((SL_LIST *)(list))->head = (node); \
}
/*******************************************************************************
*
* SLL_PUT_AT_TAIL - add node to end of list
*
* This macro adds the specified node to the end of the specified singly
* linked list.
*
* NOMANUAL
*/
#define SLL_PUT_AT_TAIL(list, node) \
{ \
((SL_NODE *)(node))->next = NULL; \
if (((SL_LIST *)(list))->head == NULL) \
{ \
((SL_LIST *)(list))->head = (SL_NODE *)(node); \
((SL_LIST *)(list))->tail = (SL_NODE *)(node); \
} \
else \
((SL_LIST *)(list))->tail->next = (SL_NODE *)(node); \
((SL_LIST *)(list))->tail = (SL_NODE *)(node); \
}
/*******************************************************************************
*
* SLL_GET - get (delete and return) first node from list
*
* This macro gets the first node from the specified singly linked list,
* deletes the node from the list, and returns a pointer to the node gotten.
*
* NOMANUAL
*/
#define SLL_GET(list, node) \
{ \
if (((node) = (void *)((SL_LIST *)(list))->head) != NULL) \
((SL_LIST *)(list))->head = ((SL_NODE *)(node))->next; \
}
/*******************************************************************************
*
* SLL_REMOVE - remove specified node in list
*
* Remove the specified node in a singly linked list.
*
* NOMANUAL
*/
#define SLL_REMOVE(list, deleteNode, previousNode) \
{ \
if (((SL_NODE *)(previousNode)) == NULL) \
{ \
((SL_LIST *)(list))->head = ((SL_NODE *)(deleteNode))->next; \
if (((SL_LIST *)(list))->tail == ((SL_NODE *)(deleteNode))) \
((SL_LIST *)(list))->tail = NULL; \
} \
else \
{ \
((SL_NODE *)(previousNode))->next = ((SL_NODE *)(deleteNode))->next; \
if (((SL_LIST *)(list))->tail == ((SL_NODE *)(deleteNode))) \
((SL_LIST *)(list))->tail = ((SL_NODE *)(previousNode)); \
} \
}
/*******************************************************************************
*
* SLL_PREVIOUS - find and return previous node in list
*
* Find and return the previous node in a singly linked list.
*
* NOMANUAL
*/
#define SLL_PREVIOUS(list, node, previousNode) \
{ \
SL_NODE *temp; \
(SL_NODE *)(previousNode) = NULL; \
temp = ((SL_LIST *)(list))->head; \
if (temp != NULL) && (temp != (node)) \
while (temp->next != NULL) \
{ \
if (temp->next == (node)) \
{ \
(SL_NODE *)(previousNode) = temp; \
break; \
} \
temp = temp->next; \
} \
}
/************************************************************************
*
* sllFirst - find first node in list
*
* DESCRIPTION
* Finds the first node in a singly linked list.
*
* RETURNS
* Pointer to the first node in a list, or
* NULL if the list is empty.
*
* NOMANUAL
*/
#define SLL_FIRST(pList) \
( \
(((SL_LIST *)pList)->head) \
)
/************************************************************************
*
* sllLast - find last node in list
*
* This routine finds the last node in a singly linked list.
*
* RETURNS
* pointer to the last node in list, or
* NULL if the list is empty.
*
* NOMANUAL
*/
#define SLL_LAST(pList) \
( \
(((SL_LIST *)pList)->tail) \
)
/************************************************************************
*
* sllNext - find next node in list
*
* Locates the node immediately after the node pointed to by the pNode.
*
* RETURNS:
* Pointer to the next node in the list, or
* NULL if there is no next node.
*
* NOMANUAL
*/
#define SLL_NEXT(pNode) \
( \
(((SL_NODE *)pNode)->next) \
)
/************************************************************************
*
* sllEmpty - boolean function to check for empty list
*
* RETURNS:
* TRUE if list is empty
* FALSE otherwise
*
* NOMANUAL
*/
#define SLL_EMPTY(pList) \
( \
(((SL_LIST *)pList)->head == NULL) \
)
/* function declarations */
extern SL_LIST *sllCreate (void);
extern SL_NODE *sllEach (SL_LIST *pList, FUNCPTR routine, int routineArg);
extern SL_NODE *sllGet (SL_LIST *pList);
extern SL_NODE *sllPrevious (SL_LIST *pList, SL_NODE *pNode);
extern STATUS sllDelete (SL_LIST *pList);
extern STATUS sllInit (SL_LIST *pList);
extern STATUS sllTerminate (SL_LIST *pList);
extern int sllCount (SL_LIST *pList);
extern void sllPutAtHead (SL_LIST *pList, SL_NODE *pNode);
extern void sllPutAtTail (SL_LIST *pList, SL_NODE *pNode);
extern void sllRemove (SL_LIST *pList, SL_NODE *pDeleteNode,
SL_NODE *pPrevNode);
#ifdef __cplusplus
}
#endif
#endif /* __INCsllLibh */