VxWorks Reference Manual : Libraries

lstLib

NAME

lstLib - doubly linked list subroutine library

ROUTINES

lstInit( ) - initialize a list descriptor
lstAdd( ) - add a node to the end of a list
lstConcat( ) - concatenate two lists
lstCount( ) - report the number of nodes in a list
lstDelete( ) - delete a specified node from a list
lstExtract( ) - extract a sublist from a list
lstFirst( ) - find first node in list
lstGet( ) - delete and return the first node from a list
lstInsert( ) - insert a node in a list after a specified node
lstLast( ) - find the last node in a list
lstNext( ) - find the next node in a list
lstNth( ) - find the Nth node in a list
lstPrevious( ) - find the previous node in a list
lstNStep( ) - find a list node nStep steps away from a specified node
lstFind( ) - find a node in a list
lstFree( ) - free up a list

DESCRIPTION

This subroutine library supports the creation and maintenance of a doubly linked list. The user supplies a list descriptor (type LIST) that will contain pointers to the first and last nodes in the list, and a count of the number of nodes in the list. The nodes in the list can be any user-defined structure, but they must reserve space for two pointers as their first elements. Both the forward and backward chains are terminated with a NULL pointer.

The linked-list library simply manipulates the linked-list data structures; no kernel functions are invoked. In particular, linked lists by themselves provide no task synchronization or mutual exclusion. If multiple tasks will access a single linked list, that list must be guarded with some mutual-exclusion mechanism (e.g., a mutual-exclusion semaphore).

NON-EMPTY LIST

   ---------             --------          --------
   | head--------------->| next----------->| next---------
   |       |             |      |          |      |      |
   |       |       ------- prev |<---------- prev |      |
   |       |       |     |      |          |      |      |
   | tail------    |     | ...  |    ----->| ...  |      |
   |       |  |    v                 |                   v
   |count=2|  |  -----               |                 -----
   ---------  |   ---                |                  ---
              |    -                 |                   -
              |                      |
              ------------------------

EMPTY LIST

        -----------
        |  head------------------
        |         |             |
        |  tail----------       |
        |         |     |       v
        | count=0 |   -----   -----
        -----------    ---     ---
                        -       -

INCLUDE FILES

lstLib.h

SEE ALSO

lstLib


Libraries : Routines

lstInit( )

NAME

lstInit( ) - initialize a list descriptor

SYNOPSIS

void lstInit
    (
    LIST * pList /* ptr to list descriptor to be initialized */
    )

DESCRIPTION

This routine initializes a specified list to an empty list.

RETURNS

N/A

SEE ALSO

lstLib


Libraries : Routines

lstAdd( )

NAME

lstAdd( ) - add a node to the end of a list

SYNOPSIS

void lstAdd
    (
    LIST * pList, /* pointer to list descriptor */
    NODE * pNode  /* pointer to node to be added */
    )

DESCRIPTION

This routine adds a specified node to the end of a specified list.

RETURNS

N/A

SEE ALSO

lstLib


Libraries : Routines

lstConcat( )

NAME

lstConcat( ) - concatenate two lists

SYNOPSIS

void lstConcat
    (
    LIST * pDstList, /* destination list */
    LIST * pAddList  /* list to be added to dstList */
    )

DESCRIPTION

This routine concatenates the second list to the end of the first list. The second list is left empty. Either list (or both) can be empty at the beginning of the operation.

RETURNS

N/A

SEE ALSO

lstLib


Libraries : Routines

lstCount( )

NAME

lstCount( ) - report the number of nodes in a list

SYNOPSIS

int lstCount
    (
    LIST * pList /* pointer to list descriptor */
    )

DESCRIPTION

This routine returns the number of nodes in a specified list.

RETURNS

The number of nodes in the list.

SEE ALSO

lstLib


Libraries : Routines

lstDelete( )

NAME

lstDelete( ) - delete a specified node from a list

SYNOPSIS

void lstDelete
    (
    LIST * pList, /* pointer to list descriptor */
    NODE * pNode  /* pointer to node to be deleted */
    )

DESCRIPTION

This routine deletes a specified node from a specified list.

RETURNS

N/A

SEE ALSO

lstLib


Libraries : Routines

lstExtract( )

NAME

lstExtract( ) - extract a sublist from a list

SYNOPSIS

void lstExtract
    (
    LIST * pSrcList,   /* pointer to source list */
    NODE * pStartNode, /* first node in sublist to be extracted */
    NODE * pEndNode,   /* last node in sublist to be extracted */
    LIST * pDstList    /* ptr to list where to put extracted list */
    )

DESCRIPTION

This routine extracts the sublist that starts with pStartNode and ends with pEndNode from a source list. It places the extracted list in pDstList.

RETURNS

N/A

SEE ALSO

lstLib


Libraries : Routines

lstFirst( )

NAME

lstFirst( ) - find first node in list

SYNOPSIS

NODE *lstFirst
    (
    LIST * pList /* pointer to list descriptor */
    )

DESCRIPTION

This routine finds the first node in a linked list.

RETURNS

A pointer to the first node in a list, or NULL if the list is empty.

SEE ALSO

lstLib


Libraries : Routines

lstGet( )

NAME

lstGet( ) - delete and return the first node from a list

SYNOPSIS

NODE *lstGet
    (
    LIST * pList /* ptr to list from which to get node */
    )

DESCRIPTION

This routine gets the first node from a specified list, deletes the node from the list, and returns a pointer to the node gotten.

RETURNS

A pointer to the node gotten, or NULL if the list is empty.

SEE ALSO

lstLib


Libraries : Routines

lstInsert( )

NAME

lstInsert( ) - insert a node in a list after a specified node

SYNOPSIS

void lstInsert
    (
    LIST * pList, /* pointer to list descriptor */
    NODE * pPrev, /* pointer to node after which to insert */
    NODE * pNode  /* pointer to node to be inserted */
    )

DESCRIPTION

This routine inserts a specified node in a specified list. The new node is placed following the list node pPrev. If pPrev is NULL, the node is inserted at the head of the list.

RETURNS

N/A

SEE ALSO

lstLib


Libraries : Routines

lstLast( )

NAME

lstLast( ) - find the last node in a list

SYNOPSIS

NODE *lstLast
    (
    LIST * pList /* pointer to list descriptor */
    )

DESCRIPTION

This routine finds the last node in a list.

RETURNS

A pointer to the last node in the list, or NULL if the list is empty.

SEE ALSO

lstLib


Libraries : Routines

lstNext( )

NAME

lstNext( ) - find the next node in a list

SYNOPSIS

NODE *lstNext
    (
    NODE * pNode /* ptr to node whose successor is to be found */
    )

DESCRIPTION

This routine locates the node immediately following a specified node.

RETURNS

A pointer to the next node in the list, or NULL if there is no next node.

SEE ALSO

lstLib


Libraries : Routines

lstNth( )

NAME

lstNth( ) - find the Nth node in a list

SYNOPSIS

NODE *lstNth
    (
    LIST * pList,  /* pointer to list descriptor */
    int    nodenum /* number of node to be found */
    )

DESCRIPTION

This routine returns a pointer to the node specified by a number nodenum where the first node in the list is numbered 1. Note that the search is optimized by searching forward from the beginning if the node is closer to the head, and searching back from the end if it is closer to the tail.

RETURNS

A pointer to the Nth node, or NULL if there is no Nth node.

SEE ALSO

lstLib


Libraries : Routines

lstPrevious( )

NAME

lstPrevious( ) - find the previous node in a list

SYNOPSIS

NODE *lstPrevious
    (
    NODE * pNode /* ptr to node whose predecessor is to be found */
    )

DESCRIPTION

This routine locates the node immediately preceding the node pointed to by pNode.

RETURNS

A pointer to the previous node in the list, or NULL if there is no previous node.

SEE ALSO

lstLib


Libraries : Routines

lstNStep( )

NAME

lstNStep( ) - find a list node nStep steps away from a specified node

SYNOPSIS

NODE *lstNStep
    (
    NODE * pNode, /* the known node */
    int    nStep  /* number of steps away to find */
    )

DESCRIPTION

This routine locates the node nStep steps away in either direction from a specified node. If nStep is positive, it steps toward the tail. If nStep is negative, it steps toward the head. If the number of steps is out of range, NULL is returned.

RETURNS

A pointer to the node nStep steps away, or NULL if the node is out of range.

SEE ALSO

lstLib


Libraries : Routines

lstFind( )

NAME

lstFind( ) - find a node in a list

SYNOPSIS

int lstFind
    (
    LIST * pList, /* list in which to search */
    NODE * pNode  /* pointer to node to search for */
    )

DESCRIPTION

This routine returns the node number of a specified node (the first node is 1).

RETURNS

The node number, or ERROR if the node is not found.

SEE ALSO

lstLib


Libraries : Routines

lstFree( )

NAME

lstFree( ) - free up a list

SYNOPSIS

void lstFree
    (
    LIST * pList /* list for which to free all nodes */
    )

DESCRIPTION

This routine turns any list into an empty list. It also frees up memory used for nodes.

RETURNS

N/A

SEE ALSO

lstLib, free( )