aboutsummaryrefslogtreecommitdiff
path: root/src/util/container_slist.c
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2010-09-08 11:14:29 +0000
committerPhilipp Tölke <toelke@in.tum.de>2010-09-08 11:14:29 +0000
commit2fb264b62b94d7999c863672b65af974d9f877e0 (patch)
tree0abfbc77dbcb573b8921e134f426bba54f6c5f54 /src/util/container_slist.c
parent125ae7244ad0fb46ab1d7cf3dfb04c8d3a8a9f19 (diff)
downloadgnunet-2fb264b62b94d7999c863672b65af974d9f877e0.tar.gz
gnunet-2fb264b62b94d7999c863672b65af974d9f877e0.zip
implemented a way to add an element to the end of a slist
Diffstat (limited to 'src/util/container_slist.c')
-rw-r--r--src/util/container_slist.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/util/container_slist.c b/src/util/container_slist.c
index fb9ab5558..8c4886ef5 100644
--- a/src/util/container_slist.c
+++ b/src/util/container_slist.c
@@ -65,6 +65,11 @@ struct GNUNET_CONTAINER_SList
65 struct GNUNET_CONTAINER_SList_Elem *head; 65 struct GNUNET_CONTAINER_SList_Elem *head;
66 66
67 /** 67 /**
68 * Tail of the linked list.
69 */
70 struct GNUNET_CONTAINER_SList_Elem *tail;
71
72 /**
68 * Number of elements in the list. 73 * Number of elements in the list.
69 */ 74 */
70 unsigned int length; 75 unsigned int length;
@@ -141,6 +146,30 @@ GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
141 e = create_elem (disp, buf, len); 146 e = create_elem (disp, buf, len);
142 e->next = l->head; 147 e->next = l->head;
143 l->head = e; 148 l->head = e;
149 if (l->tail == NULL) l->tail = e;
150 l->length++;
151}
152
153/**
154 * Add a new element to the end of the list
155 * @param l list
156 * @param disp memory disposition
157 * @param buf payload buffer
158 * @param len length of the buffer
159 */
160void
161GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
162 enum GNUNET_CONTAINER_SListDisposition disp,
163 const void *buf, size_t len)
164{
165 struct GNUNET_CONTAINER_SList_Elem *e;
166
167 e = create_elem (disp, buf, len);
168 if (l->tail != NULL)
169 l->tail->next = e;
170 if (l->head == NULL)
171 l->head = e;
172 l->tail = e;
144 l->length++; 173 l->length++;
145} 174}
146 175
@@ -228,6 +257,7 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l)
228 e = n; 257 e = n;
229 } 258 }
230 l->head = NULL; 259 l->head = NULL;
260 l->tail = NULL;
231 l->length = 0; 261 l->length = 0;
232} 262}
233 263
@@ -279,6 +309,8 @@ GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i)
279 i->last->next = next; 309 i->last->next = next;
280 else 310 else
281 i->list->head = next; 311 i->list->head = next;
312 if (next == NULL)
313 i->list->tail = i->last;
282 if (i->elem->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) 314 if (i->elem->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC)
283 GNUNET_free (i->elem->elem); 315 GNUNET_free (i->elem->elem);
284 GNUNET_free (i->elem); 316 GNUNET_free (i->elem);
@@ -307,6 +339,8 @@ GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
307 before->last->next = e; 339 before->last->next = e;
308 else 340 else
309 before->list->head = e; 341 before->list->head = e;
342 if (e->next == NULL)
343 before->list->tail = e;
310 before->list->length++; 344 before->list->length++;
311} 345}
312 346