109 } |
110 } |
110 |
111 |
111 return s; |
112 return s; |
112 } |
113 } |
113 |
114 |
114 void ucx_dlist_foreach(UcxDlist *l, ucx_callback fnc, void* data) { |
|
115 UcxDlist *e = l; |
|
116 while (e != NULL) { |
|
117 fnc(e, data); |
|
118 e = e->next; |
|
119 } |
|
120 } |
|
121 |
|
122 /* dlist specific functions */ |
115 /* dlist specific functions */ |
123 UcxDlist *ucx_dlist_first(UcxDlist *l) { |
116 UcxDlist *ucx_dlist_first(UcxDlist *l) { |
124 if (l == NULL) return NULL; |
117 if (l == NULL) return NULL; |
125 |
118 |
126 UcxDlist *e = l; |
119 UcxDlist *e = l; |
127 while (e->prev != NULL) { |
120 while (e->prev != NULL) { |
128 e = e->prev; |
121 e = e->prev; |
129 } |
122 } |
130 return e; |
123 return e; |
131 } |
124 } |
|
125 |
|
126 UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) { |
|
127 if (e->prev == NULL) { |
|
128 if(e->next != NULL) { |
|
129 e->next->prev = NULL; |
|
130 l = e->next; |
|
131 } else { |
|
132 l = NULL; |
|
133 } |
|
134 |
|
135 } else { |
|
136 e->prev->next = e->next; |
|
137 e->next->prev = e->prev; |
|
138 } |
|
139 free(e); |
|
140 return l; |
|
141 } |