js/src/jsclist.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef jsclist_h
michael@0 8 #define jsclist_h
michael@0 9
michael@0 10 #include "jstypes.h"
michael@0 11
michael@0 12 /*
michael@0 13 ** Circular linked list
michael@0 14 */
michael@0 15 typedef struct JSCListStr {
michael@0 16 struct JSCListStr *next;
michael@0 17 struct JSCListStr *prev;
michael@0 18 } JSCList;
michael@0 19
michael@0 20 /*
michael@0 21 ** Insert element "_e" into the list, before "_l".
michael@0 22 */
michael@0 23 #define JS_INSERT_BEFORE(_e,_l) \
michael@0 24 JS_BEGIN_MACRO \
michael@0 25 (_e)->next = (_l); \
michael@0 26 (_e)->prev = (_l)->prev; \
michael@0 27 (_l)->prev->next = (_e); \
michael@0 28 (_l)->prev = (_e); \
michael@0 29 JS_END_MACRO
michael@0 30
michael@0 31 /*
michael@0 32 ** Insert element "_e" into the list, after "_l".
michael@0 33 */
michael@0 34 #define JS_INSERT_AFTER(_e,_l) \
michael@0 35 JS_BEGIN_MACRO \
michael@0 36 (_e)->next = (_l)->next; \
michael@0 37 (_e)->prev = (_l); \
michael@0 38 (_l)->next->prev = (_e); \
michael@0 39 (_l)->next = (_e); \
michael@0 40 JS_END_MACRO
michael@0 41
michael@0 42 /*
michael@0 43 ** Return the element following element "_e"
michael@0 44 */
michael@0 45 #define JS_NEXT_LINK(_e) \
michael@0 46 ((_e)->next)
michael@0 47 /*
michael@0 48 ** Return the element preceding element "_e"
michael@0 49 */
michael@0 50 #define JS_PREV_LINK(_e) \
michael@0 51 ((_e)->prev)
michael@0 52
michael@0 53 /*
michael@0 54 ** Append an element "_e" to the end of the list "_l"
michael@0 55 */
michael@0 56 #define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l)
michael@0 57
michael@0 58 /*
michael@0 59 ** Insert an element "_e" at the head of the list "_l"
michael@0 60 */
michael@0 61 #define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l)
michael@0 62
michael@0 63 /* Return the head/tail of the list */
michael@0 64 #define JS_LIST_HEAD(_l) (_l)->next
michael@0 65 #define JS_LIST_TAIL(_l) (_l)->prev
michael@0 66
michael@0 67 /*
michael@0 68 ** Remove the element "_e" from it's circular list.
michael@0 69 */
michael@0 70 #define JS_REMOVE_LINK(_e) \
michael@0 71 JS_BEGIN_MACRO \
michael@0 72 (_e)->prev->next = (_e)->next; \
michael@0 73 (_e)->next->prev = (_e)->prev; \
michael@0 74 JS_END_MACRO
michael@0 75
michael@0 76 /*
michael@0 77 ** Remove the element "_e" from it's circular list. Also initializes the
michael@0 78 ** linkage.
michael@0 79 */
michael@0 80 #define JS_REMOVE_AND_INIT_LINK(_e) \
michael@0 81 JS_BEGIN_MACRO \
michael@0 82 (_e)->prev->next = (_e)->next; \
michael@0 83 (_e)->next->prev = (_e)->prev; \
michael@0 84 (_e)->next = (_e); \
michael@0 85 (_e)->prev = (_e); \
michael@0 86 JS_END_MACRO
michael@0 87
michael@0 88 /*
michael@0 89 ** Return non-zero if the given circular list "_l" is empty, zero if the
michael@0 90 ** circular list is not empty
michael@0 91 */
michael@0 92 #define JS_CLIST_IS_EMPTY(_l) \
michael@0 93 ((_l)->next == (_l))
michael@0 94
michael@0 95 /*
michael@0 96 ** Initialize a circular list
michael@0 97 */
michael@0 98 #define JS_INIT_CLIST(_l) \
michael@0 99 JS_BEGIN_MACRO \
michael@0 100 (_l)->next = (_l); \
michael@0 101 (_l)->prev = (_l); \
michael@0 102 JS_END_MACRO
michael@0 103
michael@0 104 #define JS_INIT_STATIC_CLIST(_l) \
michael@0 105 {(_l), (_l)}
michael@0 106
michael@0 107 #endif /* jsclist_h */

mercurial