-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclist.c
58 lines (50 loc) · 985 Bytes
/
clist.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* clist.c
*
* Implementation for the atom list.
*/
#include <stdlib.h>
#include <assert.h>
#include "atom.h"
#include "clist.h"
struct _clist {
int index;
atom_t* pointer;
clist_t* next;
};
clist_t* clist_next(clist_t* prev) {
assert(prev);
return prev->next;
}
atom_t* clist_pointer(clist_t* curr) {
assert(curr);
return curr->pointer;
}
int clist_index(clist_t* curr) {
assert(curr);
return curr->index;
}
clist_t* clist_new(clist_t* prev, atom_t* c, int i) {
if (prev && !prev->pointer) {
prev->pointer = c;
prev->index = i;
return prev;
}
clist_t* newone = malloc(sizeof(clist_t));
assert(newone);
newone->next = NULL;
if (!prev) {
newone->pointer = NULL;
newone->index = -1;
} else {
newone->pointer = c;
newone->index = i;
}
return newone;
}
void clist_free(clist_t* node) {
while (node) {
clist_t* next = node->next;
free(node);
node = next;
}
}