21:d599fefc7620 | 22:76cdd8209f1f |
---|---|
43 if (nl == NULL) return NULL; | 43 if (nl == NULL) return NULL; |
44 | 44 |
45 nl->data = data; | 45 nl->data = data; |
46 nl->next = NULL; | 46 nl->next = NULL; |
47 if (l == NULL) { | 47 if (l == NULL) { |
48 nl->prev = NULL; | |
48 return nl; | 49 return nl; |
49 } else { | 50 } else { |
50 UcxDlist *t = ucx_dlist_last(l); | 51 UcxDlist *t = ucx_dlist_last(l); |
51 t->next = nl; | 52 t->next = nl; |
52 nl->prev = t; | 53 nl->prev = t; |
111 return s; | 112 return s; |
112 } | 113 } |
113 | 114 |
114 void ucx_dlist_foreach(UcxDlist *l, ucx_callback fnc, void* data) { | 115 void ucx_dlist_foreach(UcxDlist *l, ucx_callback fnc, void* data) { |
115 UcxDlist *e = l; | 116 UcxDlist *e = l; |
117 UcxDlist *n; | |
116 while (e != NULL) { | 118 while (e != NULL) { |
119 n = e->next; | |
117 fnc(e, data); | 120 fnc(e, data); |
118 e = e->next; | 121 e = n; |
119 } | 122 } |
120 } | 123 } |
121 | 124 |
122 /* dlist specific functions */ | 125 /* dlist specific functions */ |
123 UcxDlist *ucx_dlist_first(UcxDlist *l) { | 126 UcxDlist *ucx_dlist_first(UcxDlist *l) { |
127 while (e->prev != NULL) { | 130 while (e->prev != NULL) { |
128 e = e->prev; | 131 e = e->prev; |
129 } | 132 } |
130 return e; | 133 return e; |
131 } | 134 } |
135 | |
136 UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) { | |
137 if (e->prev == NULL) { | |
138 e->next->prev = NULL; | |
139 l = e->next; | |
140 } else { | |
141 e->prev->next = e->next; | |
142 e->next->prev = e->prev; | |
143 } | |
144 free(e); | |
145 return l; | |
146 } |