src/server/ucx/dlist.c

changeset 30
27c7511c0e34
parent 15
cff9c4101dd7
child 36
450d2d5f4735
equal deleted inserted replaced
29:e8619defde14 30:27c7511c0e34
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;
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 }

mercurial