-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
56 lines (41 loc) · 1.48 KB
/
list.h
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
#pragma once
typedef volatile struct lanchor lanchor;
struct lanchor{
lanchor *n;
lanchor *p;
};
#define LANCHOR(l) { \
(l) ? &((list *) (l))->nil : NULL, \
(l) ? &((list *) (l))->nil : NULL \
}
typedef volatile struct list{
struct lanchor nil;
uptr size;
} list;
#define LIST(l, elem) { \
{(elem) ? (elem) : &(l)->nil , \
(elem) ? (elem) : &(l)->nil} \
}
#define LIST_FOR_EACH(cur, list) \
for(cur = list->nil.n; cur != &list->nil; cur = cur->n)
void list_push(lanchor *a, list *l);
void list_enq(lanchor *a, list *l);
void list_add_before(lanchor *a, lanchor *beforehis, list *l);
void list_add_after(lanchor *a, lanchor *afterhis, list *l);
void list_del(lanchor *a, list *l);
typedef bool (* lpred)(lanchor *to_compare, void *key);
lanchor *list_find(lpred pred, void *key, list *list);
int list_contains(lanchor *anchor, list *list);
lanchor *list_nth(unsigned int n, list *list);
lanchor *list_deq(list *l);
lanchor *list_peek(list *l);
lanchor *list_unenq(list *l);
uptr list_size(list *list);
lanchor *circlist_next(lanchor *a, list *l);
lanchor *circlist_prev(lanchor *a, list *l);
int lanchor_unused(lanchor *a);
int lanchor_valid(lanchor *a, list *list);
#define pudef (struct lanchor, "{%, %}", a->n, a->p)
#include <pudef.h>
#define pudef (struct list, "LIST{%, sz=%}", a->nil, a->size)
#include <pudef.h>