New function list_replace(), to replace a list element in-place.
authorBen Pfaff <blp@nicira.com>
Thu, 27 Mar 2008 22:11:01 +0000 (15:11 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 28 Mar 2008 00:50:33 +0000 (17:50 -0700)
include/list.h
lib/list.c

index 09b6098..7272011 100644 (file)
@@ -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 *);
index 379e8f8..a05778d 100644 (file)
@@ -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 *