forked from emersion/libliftoff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
43 lines (36 loc) · 728 Bytes
/
list.c
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
#include "list.h"
void liftoff_list_init(struct liftoff_list *list)
{
list->prev = list;
list->next = list;
}
void liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm)
{
elm->prev = list;
elm->next = list->next;
list->next = elm;
elm->next->prev = elm;
}
void liftoff_list_remove(struct liftoff_list *elm)
{
elm->prev->next = elm->next;
elm->next->prev = elm->prev;
elm->next = NULL;
elm->prev = NULL;
}
size_t liftoff_list_length(const struct liftoff_list *list)
{
struct liftoff_list *e;
size_t count;
count = 0;
e = list->next;
while (e != list) {
e = e->next;
count++;
}
return count;
}
bool liftoff_list_empty(const struct liftoff_list *list)
{
return list->next == list;
}