The Mozilla
Organization
Our Mission
Who We Are
Getting Involved
Community
Editorials
What's New
Newsbot
Development
Roadmap
Module Owners
Blue Sky
Projects
Status
Tools
Products
Source Code
Binaries
Documentation
License Terms
Bug Reports
Quality
Search
Feedback


[Contents] [Previous] [Next] [Last]



Chapter 22
Linked Lists

This chapter describes the NSPR API for managing linked lists. The API is a set of macros for initializing a circular (doubly linked) list, inserting and removing elements from the list. The macros are not thread safe and the caller has to provide to mutually-exclusive access to the list and the nodes being added/removed from the list.

Types

PRCList

A circular linked list.
Syntax
#include <prclist.h>

typedef struct PRCListStr PRCList;

struct PRCListStr {
    PRCList *next;
    PRCList *prev;
};
Description
PRClist defines a node in a circular linked list. It can be used as the anchor of a list and can be embedded in data structures that are maintained in a linked list.

Macros

PR_INIT_CLIST

Initialize a circular list.
Syntax
#include <prclist.h>

PR_INIT_CLIST(PRCList *listp);
Parameters
The macro has the following parameters:
listp Pointer to the anchor of the linked list.
Description
PR_INIT_CLIST initializes the list pointed to by listp to be an empty list.

PR_INIT_STATIC_CLIST

Statically Initialize a circular list.
Syntax
#include <prclist.h>

PR_INIT_STATIC_CLIST(PRCList *listp);
Parameters
The macro has the following parameters:
listp Pointer to the anchor of the linked list.
Description
PR_INIT_STATIC_CLIST statically initializes the list pointed to by listp to be an empty list. For example,
PRCList free_object_list = PR_INIT_STATIC_CLIST(&free_object_list);

PR_APPEND_LINK

Append an element to the end of the list.
Syntax
#include <prclist.h>

PR_APPEND_LINK(PRCList *elemp, PRCList *listp);
Parameters
The macro has the following parameters:
elemp Pointer to the element to be inserted.
listp Pointer to the list.
Description
PR_APPEND_LINK adds the element pointed to by elemp to the end of the list pointed to by listp.

PR_INSERT_LINK

Insert an element at the head of the list.
Syntax
#include <prclist.h>

PR_INSERT_LINK(PRCList *elemp, PRCList *listp);
Parameters
The macro has the following parameters:
elemp Pointer to the element to be inserted.
listp Pointer to the list.
Description
PR_INSERT_LINK inserts the element pointed to by elemp at the head of the list pointed to by listp.

PR_NEXT_LINK

Return the next element in the list.
Syntax
#include <prclist.h>

PR_NEXT_LINK(PRCList *elemp);
Parameters
The macro has the following parameters:
elemp Pointer to the element.
Description
PR_NEXT_LINK returns a pointer to the element following the one pointed to by elemp and can be used to traverse the list. The following element is not removed from the list.

PR_PREV_LINK

Return the preceding element in the list.
Syntax
#include <prclist.h>

PR_PREV_LINK(PRCList *elemp);
Parameters
The macro has the following parameters:
elemp Pointer to the element.
Description
PR_NEXT_LINK returns a pointer to the element preceding the one pointed to by elemp and can be used to traverse the list. The preceding element is not removed from the list.

PR_REMOVE_LINK

Remove an element from the circular list.
Syntax
#include <prclist.h>

PR_REMOVE_LINK(PRCList *elemp);
Parameters
The macro has the following parameters:
elemp Pointer to the element.
Description
PR_REMOVE_LINK removes the element pointed to by elemp from it's circular list.

PR_REMOVE_AND_INIT_LINK

Remove an element from the circular list and initialize the linkage.
Syntax
#include <prclist.h>

PR_REMOVE_AND_INIT_LINK(PRCList *elemp);
Parameters
The macro has the following parameters:
elemp Pointer to the element.
Description
PR_REMOVE_AND_INIT_LINK removes the element pointed to by elemp from it's circular list and initializes the links of the element to point to itself.

PR_INSERT_BEFORE

Insert an element before another element in the circular list.
Syntax
#include <prclist.h>

PR_INSERT_BEFORE(PRCList *elemp1, PRCList *elemp2);
Parameters
The macro has the following parameters:
elemp1 Pointer to the element to be inserted.
elemp2 Pointer to the element before which elemp2 is to be inserted.
Description
PR_INSERT_BEFORE inserts elemp1 into the circular list, before elemp2.

PR_INSERT_AFTER

Insert an element after another element in the circular list.
Syntax
#include <prclist.h>

PR_INSERT_AFTER(PRCList *elemp1, PRCList *elemp2);
Parameters
The macro has the following parameters:
elemp1 Pointer to the element to be inserted.
elemp2 Pointer to the element after which elemp2 is to be inserted.
Description
PR_INSERT_AFTER inserts elemp1 into the circular list, after elemp2.

PR_CLIST_IS_EMPTY

Check for an empty circular list.
Syntax
#include <prclist.h>

PR_CLIST_IS_EMPTY(PRCList *listp);
Parameters
The macro has the following parameters:
listp pointer to the linked list.
Description
PR_CLIST_IS_EMPTY returns a non-zero value if the list pointed to by listp is an empty list, otherwise returns zero.

PR_LIST_HEAD

Return the head of the circular list.
Syntax
#include <prclist.h>

PR_LIST_HEAD(PRCList *listp);
Parameters
The macro has the following parameters:
listp Pointer to the linked list.
Description
PR_LIST_HEAD returns the head of the circular list.

PR_LIST_TAIL

Return the tail of the circular list.
Syntax
#include <prclist.h>

PR_LIST_TAIL(PRCList *listp);
Parameters
The macro has the following parameters:
listp Pointer to the linked list.
Description
PR_LIST_TAIL returns the tail of the circular list.


[Contents] [Previous] [Next] [Last]
Last Updated: Tue Jul 14 17:31:16 PDT 1998
Copyright © 1998 Netscape Communications Corporation



Copyright © 1998 The Mozilla Organization.