1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
13 ** Circular linked list
15 typedef struct JSCListStr
{
16 struct JSCListStr
* next
;
17 struct JSCListStr
* prev
;
21 ** Insert element "_e" into the list, before "_l".
23 #define JS_INSERT_BEFORE(_e,_l) \
26 (_e)->prev = (_l)->prev; \
27 (_l)->prev->next = (_e); \
32 ** Insert element "_e" into the list, after "_l".
34 #define JS_INSERT_AFTER(_e,_l) \
36 (_e)->next = (_l)->next; \
38 (_l)->next->prev = (_e); \
43 ** Return the element following element "_e"
45 #define JS_NEXT_LINK(_e) \
48 ** Return the element preceding element "_e"
50 #define JS_PREV_LINK(_e) \
54 ** Append an element "_e" to the end of the list "_l"
56 #define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l)
59 ** Insert an element "_e" at the head of the list "_l"
61 #define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l)
63 /* Return the head/tail of the list */
64 #define JS_LIST_HEAD(_l) (_l)->next
65 #define JS_LIST_TAIL(_l) (_l)->prev
68 ** Remove the element "_e" from it's circular list.
70 #define JS_REMOVE_LINK(_e) \
72 (_e)->prev->next = (_e)->next; \
73 (_e)->next->prev = (_e)->prev; \
77 ** Remove the element "_e" from it's circular list. Also initializes the
80 #define JS_REMOVE_AND_INIT_LINK(_e) \
82 (_e)->prev->next = (_e)->next; \
83 (_e)->next->prev = (_e)->prev; \
89 ** Return non-zero if the given circular list "_l" is empty, zero if the
90 ** circular list is not empty
92 #define JS_CLIST_IS_EMPTY(_l) \
93 bool((_l)->next == (_l))
96 ** Initialize a circular list
98 #define JS_INIT_CLIST(_l) \
104 #define JS_INIT_STATIC_CLIST(_l) \
107 #endif /* jsclist_h */