Revision 316
documented list and queue
list.c | ||
---|---|---|
6 | 6 |
list_node_t *p, *n; |
7 | 7 |
void *val; |
8 | 8 |
}; |
9 |
|
|
9 | 10 |
list_node_t* (list_node_ctor)(list_node_t *p, list_node_t *n, void *val){ |
10 | 11 |
list_node_t *ret = malloc(sizeof(list_node_t)); |
11 | 12 |
if(ret == NULL) return NULL; |
... | ... | |
14 | 15 |
ret->val = val; |
15 | 16 |
return ret; |
16 | 17 |
} |
17 |
void (list_node_dtor)(list_node_t *p){ |
|
18 |
void (list_node_dtor)(list_node_t *p){
|
|
18 | 19 |
free(p); |
19 | 20 |
} |
20 | 21 |
list_node_t* (list_node_next)(const list_node_t *p){ return p->n; } |
... | ... | |
26 | 27 |
list_node_t *end_; |
27 | 28 |
size_t sz; |
28 | 29 |
}; |
29 |
list_t* (list_ctor)(void){ |
|
30 |
|
|
31 |
list_t* (list_ctor) (void){ |
|
30 | 32 |
list_t *ret = malloc(sizeof(list_t)); |
31 | 33 |
if(ret == NULL) return NULL; |
32 | 34 |
ret->sz = 0; |
... | ... | |
41 | 43 |
ret->end_ ->p = ret->begin_; |
42 | 44 |
return ret; |
43 | 45 |
} |
44 |
int (list_dtor)(list_t *l){
|
|
46 |
int (list_dtor) (list_t *l){
|
|
45 | 47 |
if(l == NULL) return 0; |
46 | 48 |
if(list_size(l) > 0) return 1; |
47 | 49 |
list_node_dtor(l->begin_); |
... | ... | |
49 | 51 |
free(l); |
50 | 52 |
return 0; |
51 | 53 |
} |
52 |
list_node_t* (list_begin )( list_t *l){ return l->begin_->n; }
|
|
53 |
list_node_t* (list_end )( list_t *l){ return l->end_; }
|
|
54 |
size_t (list_size )(const list_t *l){ return l->sz; }
|
|
55 |
int (list_empty )(const list_t *l){ return !(l->sz); }
|
|
56 |
list_node_t* (list_insert)(list_t *l, list_node_t *position, void *val){ |
|
54 |
list_node_t* (list_begin) (list_t *l){ return l->begin_->n; }
|
|
55 |
list_node_t* (list_end) (list_t *l){ return l->end_; }
|
|
56 |
size_t (list_size) (const list_t *l){ return l->sz; }
|
|
57 |
int (list_empty) (const list_t *l){ return (l->sz ? true : false); }
|
|
58 |
list_node_t* (list_insert) (list_t *l, list_node_t *position, void *val){
|
|
57 | 59 |
list_node_t *node = list_node_ctor(position->p, position, val); |
58 | 60 |
position->p->n = node; |
59 | 61 |
position->p = node; |
60 | 62 |
++l->sz; |
61 | 63 |
return node; |
62 | 64 |
} |
63 |
void* (list_erase )(list_t *l, list_node_t *position){
|
|
65 |
void* (list_erase) (list_t *l, list_node_t *position){
|
|
64 | 66 |
position->p->n = position->n; |
65 | 67 |
position->n->p = position->p; |
66 | 68 |
void *ret = position->val; |
... | ... | |
71 | 73 |
void (list_push_back)(list_t *l, void *val){ |
72 | 74 |
list_insert(l, list_end(l), val); |
73 | 75 |
} |
74 |
void** (list_front)(list_t *l){ |
|
76 |
void** (list_front) (list_t *l){
|
|
75 | 77 |
return list_node_val(list_begin(l)); |
76 | 78 |
} |
77 | 79 |
void (list_pop_front)(list_t *l){ |
78 | 80 |
list_erase(l, list_begin(l)); |
79 | 81 |
} |
80 |
list_node_t* (list_find)(list_t *l, void *val){ |
|
82 |
list_node_t* (list_find) (list_t *l, void *val){
|
|
81 | 83 |
list_node_t *it = list_begin(l); |
82 | 84 |
while(it != list_end(l) && *list_node_val(it) != val){ |
83 | 85 |
it = list_node_next(it); |
Also available in: Unified diff