From: Ben Pfaff Date: Thu, 27 Mar 2008 22:11:01 +0000 (-0700) Subject: New function list_replace(), to replace a list element in-place. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee5d466f7f921cf3a877bb383700f63213061b60;p=openvswitch New function list_replace(), to replace a list element in-place. --- diff --git a/include/list.h b/include/list.h index 09b60989..72720111 100644 --- a/include/list.h +++ b/include/list.h @@ -23,6 +23,7 @@ void list_insert(struct list *, struct list *); void list_splice(struct list *before, struct list *first, struct list *last); void list_push_front(struct list *, struct list *); void list_push_back(struct list *, struct list *); +void list_replace(struct list *, const struct list *); /* List removal. */ struct list *list_remove(struct list *); diff --git a/lib/list.c b/lib/list.c index 379e8f8a..a05778d1 100644 --- a/lib/list.c +++ b/lib/list.c @@ -54,6 +54,17 @@ list_push_back(struct list *list, struct list *elem) list_insert(list, elem); } +/* Puts 'elem' in the position currently occupied by 'position'. + * Afterward, 'position' is not part of a list. */ +void +list_replace(struct list *element, const struct list *position) +{ + element->next = position->next; + element->next->prev = element; + element->prev = position->prev; + element->prev->next = element; +} + /* Removes 'elem' from its list and returns the element that followed it. Undefined behavior if 'elem' is not in a list. */ struct list *