-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.h
More file actions
294 lines (190 loc) · 6.21 KB
/
LinkedList.h
File metadata and controls
294 lines (190 loc) · 6.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
2020 © Copyright (c) BiDaE Technology Inc.
Provided under BiDaE SHAREWARE LICENSE-1.0 in the LICENSE.
Project Name:
BeDIS
File Name:
LinkedList.h
File Description:
This header file contains the function declarations and variables used in
the LinkedList.c file.
Version:
2.0, 20190826
Abstract:
BeDIS uses LBeacons to deliver 3D coordinates and textual descriptions of
their locations to users' devices. Basically, a LBeacon is an inexpensive,
Bluetooth Smart Ready device. The 3D coordinates and location description
of every LBeacon are retrieved from BeDIS (Building/environment Data and
Information System) and stored locally during deployment and maintenance
times. Once initialized, each LBeacon broadcasts its coordinates and
location description to Bluetooth enabled user devices within its coverage
area.
Authors:
Han Wang , hollywang@iis.sinica.edu.tw
Joey Zhou , joeyzhou@iis.sinica.edu.tw
Gary Xiao , garyh0205@hotmail.com
Chun-Yu Lai , chunyu1202@gmail.com
*/
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_MSC_VER)
#define inline __inline
#endif
/* CONSTANTS */
/*Macro for calculating the offset of two addresses*/
#define offsetof(type, member) ((size_t) &((type *)0)->member)
/*Macro for geting the master struct from the sub struct */
#define ListEntry(ptr,type,member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
/*Macro for the method going through the list structure */
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/*Macro for the method going through the list structure reversely */
#define list_for_each_reverse(pos, head) \
for (pos = (head)->prev; pos != (head); pos = pos->prev)
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
#define list_for_each_safe_reverse(pos, n, head) \
for (pos = (head)->prev, n = pos->prev; pos != (head); \
pos = n, n = pos->prev)
/*Struct for the head of a list or doubly linked list entry used in link a
node in to a list */
typedef struct List_Entry {
struct List_Entry *next;
struct List_Entry *prev;
}List_Entry;
/* FUNCTIONS */
/*
init_list:
This function initializes the list.
Parameters:
entry: the head of the list for determining which list is goning to be
initialized.
Return value:
None
*/
inline void init_entry(List_Entry *entry) {
entry->next = entry;
entry->prev = entry;
}
/*
insert_entry_list:
This function inserts a node at where specified by the previous and next
pointers.
Parameters:
new_node: the struct of list entry for the node be added into the list.
prev: the list entry pointing to the previous node of the new node.
next: the list entry pointing to the next node of the new node.
Return value:
None
*/
inline void insert_entry_list(List_Entry *new_node, List_Entry *prev,
List_Entry *next) {
next->prev = new_node;
new_node->next = next;
new_node->prev = prev;
prev->next = new_node;
}
/*
is_isolated_node:
This function checks if the input node is isolated.
Parameters:
node - the node to be checked
Return value:
bool - Return true if the node is isolated. Otherwise, false if returned.
*/
inline bool is_isolated_node(List_Entry *node) {
return (node == node->next);
}
/*
is_entry_list_empty:
This function checks if the input List_Entry is empty.
Parameters:
entry - the struct of list entry to be checked
Return value:
bool - Return true if the list is empty. Otherwise, false if returned.
*/
inline bool is_entry_list_empty(List_Entry *entry) {
return is_isolated_node(entry);
}
/*
insert_list_first:
This function calls inserts a new node at the head of a specified list.
Parameters:
new_node: a pointer to the new node to be inserted into the list.
head: The head of list.
Return value:
None
*/
inline void insert_list_first(List_Entry *new_node, List_Entry *head) {
insert_entry_list(new_node, head, head->next);
}
/*
insert_list_tail:
This function inserts a new node at the tail of the specified list.
Parameters:
new_node: the list entry of the node be inserted into the list.
head: The head of list.
Return value:
None
*/
inline void insert_list_tail(List_Entry *new_node, List_Entry *head) {
insert_entry_list(new_node, head->prev, head);
}
/*
remove_entry_list:
This function changes the links between the node and the node which
is going to be removed.
Parameters:
prev: the struct of list entry for the node which is going to be removed
points to previously.
next: the struct of list entry for the node which is going to be removed
points to next.
Return value:
None
*/
inline void remove_entry_list(List_Entry *prev, List_Entry *next) {
next->prev = prev;
prev->next = next;
}
/*
remove_list_node:
This function calls the function of removed_node_ptrs to delete a node in
the list.
Parameters:
removed_node_ptrs - the struct of list entry for the node is going to be
removed.
Return value:
None
*/
inline void remove_list_node(List_Entry *removed_node_ptrs) {
remove_entry_list(removed_node_ptrs->prev, removed_node_ptrs->next);
removed_node_ptrs->prev = removed_node_ptrs;
removed_node_ptrs->next = removed_node_ptrs;
}
/*
concat_list:
This function concates two lists.
Parameters:
first_list_head: The head of list.
second_list_head: The head of list to be append to the first_list_head.
Return value:
None
*/
void concat_list(List_Entry *first_list_head, List_Entry *second_list_head);
/*
get_list_length:
This function returns the length of the list.
Parameters:
entry: the head of the list for determining which list is goning to be
modified.
Return value:
length: number of nodes in the list.
*/
int get_list_length(List_Entry *entry);
#endif