BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
2 * @file SLinkedList_impl.h
3 * @author Ambroz Bizjak <ambrop7@gmail.com>
4 *
5 * @section LICENSE
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29  
30 #include "SLinkedList_header.h"
31  
32 static void SLinkedListMarkRemoved (SLinkedListEntry *entry)
33 {
34 ASSERT(entry)
35  
36 SLinkedList_next(entry) = entry;
37 }
38  
39 static int SLinkedListIsRemoved (SLinkedListEntry *entry)
40 {
41 ASSERT(entry)
42  
43 return (entry == SLinkedList_next(entry));
44 }
45  
46 static void SLinkedList_Init (SLinkedList *o)
47 {
48 o->first = NULL;
49 }
50  
51 static SLinkedListEntry * SLinkedList_Next (SLinkedList *o, SLinkedListEntry *entry)
52 {
53 ASSERT(entry)
54  
55 return SLinkedList_next(entry);
56 }
57  
58 static SLinkedListEntry * SLinkedList_Prev (SLinkedList *o, SLinkedListEntry *entry)
59 {
60 ASSERT(entry)
61  
62 return (entry == o->first) ? NULL : SLinkedList_prev(entry);
63 }
64  
65 static void SLinkedList_Prepend (SLinkedList *o, SLinkedListEntry *entry)
66 {
67 ASSERT(entry)
68  
69 SLinkedList_next(entry) = o->first;
70 if (o->first) {
71 SLinkedList_prev(o->first) = entry;
72 } else {
73 #if SLINKEDLIST_PARAM_FEATURE_LAST
74 o->last = entry;
75 #endif
76 }
77 o->first = entry;
78 }
79  
80 #if SLINKEDLIST_PARAM_FEATURE_LAST
81 static void SLinkedList_Append (SLinkedList *o, SLinkedListEntry *entry)
82 {
83 ASSERT(entry)
84  
85 SLinkedList_next(entry) = NULL;
86 if (o->first) {
87 SLinkedList_prev(entry) = o->last;
88 SLinkedList_next(o->last) = entry;
89 } else {
90 o->first = entry;
91 }
92 o->last = entry;
93 }
94 #endif
95  
96 static void SLinkedList_InsertBefore (SLinkedList *o, SLinkedListEntry *entry, SLinkedListEntry *before_entry)
97 {
98 ASSERT(entry)
99 ASSERT(before_entry)
100  
101 SLinkedList_next(entry) = before_entry;
102 if (before_entry != o->first) {
103 SLinkedList_prev(entry) = SLinkedList_prev(before_entry);
104 SLinkedList_next(SLinkedList_prev(before_entry)) = entry;
105 } else {
106 o->first = entry;
107 }
108 SLinkedList_prev(before_entry) = entry;
109 }
110  
111 static void SLinkedList_InsertAfter (SLinkedList *o, SLinkedListEntry *entry, SLinkedListEntry *after_entry)
112 {
113 ASSERT(entry)
114 ASSERT(after_entry)
115  
116 SLinkedList_next(entry) = SLinkedList_next(after_entry);
117 SLinkedList_prev(entry) = after_entry;
118 if (SLinkedList_next(after_entry)) {
119 SLinkedList_prev(SLinkedList_next(after_entry)) = entry;
120 } else {
121 #if SLINKEDLIST_PARAM_FEATURE_LAST
122 o->last = entry;
123 #endif
124 }
125 SLinkedList_next(after_entry) = entry;
126 }
127  
128 static void SLinkedList_Remove (SLinkedList *o, SLinkedListEntry *entry)
129 {
130 if (entry != o->first) {
131 SLinkedList_next(SLinkedList_prev(entry)) = SLinkedList_next(entry);
132 if (SLinkedList_next(entry)) {
133 SLinkedList_prev(SLinkedList_next(entry)) = SLinkedList_prev(entry);
134 } else {
135 #if SLINKEDLIST_PARAM_FEATURE_LAST
136 o->last = SLinkedList_prev(entry);
137 #endif
138 }
139 } else {
140 o->first = SLinkedList_next(entry);
141 }
142 }
143  
144 static void SLinkedList_RemoveFirst (SLinkedList *o)
145 {
146 ASSERT(o->first)
147  
148 o->first = SLinkedList_next(o->first);
149 }
150  
151 #if SLINKEDLIST_PARAM_FEATURE_LAST
152 static void SLinkedList_RemoveLast (SLinkedList *o)
153 {
154 ASSERT(o->first)
155  
156 if (o->last == o->first) {
157 o->first = NULL;
158 } else {
159 SLinkedList_next(SLinkedList_prev(o->last)) = NULL;
160 o->last = SLinkedList_prev(o->last);
161 }
162 }
163 #endif
164  
165 static SLinkedListEntry * SLinkedList_First (const SLinkedList *o)
166 {
167 return o->first;
168 }
169  
170 #if SLINKEDLIST_PARAM_FEATURE_LAST
171 static SLinkedListEntry * SLinkedList_Last (const SLinkedList *o)
172 {
173 return (!o->first ? NULL : o->last);
174 }
175 #endif
176  
177 static int SLinkedList_IsEmpty (const SLinkedList *o)
178 {
179 return !o->first;
180 }
181  
182 #include "SLinkedList_footer.h"