summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-01-20 12:57:18 +0100
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2017-01-20 12:57:18 +0100
commit82d947a8321737108f545a25f91d7d50d10e831d (patch)
tree34abfafbe23baa3980ada8fc0517abfaff670cd9
parente43f8026923e57a5a61bff29254399fd68119f1d (diff)
downloadouroboros-82d947a8321737108f545a25f91d7d50d10e831d.tar.gz
ouroboros-82d947a8321737108f545a25f91d7d50d10e831d.zip
lib: Add move operation for lists
Allows moving the elements of one linked list to another. Re-initializes the source list.
-rw-r--r--include/ouroboros/list.h3
-rw-r--r--src/lib/list.c11
2 files changed, 14 insertions, 0 deletions
diff --git a/include/ouroboros/list.h b/include/ouroboros/list.h
index 824e6684..5f246775 100644
--- a/include/ouroboros/list.h
+++ b/include/ouroboros/list.h
@@ -54,6 +54,9 @@ void list_add_tail(struct list_head * e,
void list_del(struct list_head * e);
+void list_move(struct list_head * dst,
+ struct list_head * src);
+
bool list_is_empty(struct list_head * h);
#endif
diff --git a/src/lib/list.c b/src/lib/list.c
index 908d3b71..01fdf6e3 100644
--- a/src/lib/list.c
+++ b/src/lib/list.c
@@ -70,3 +70,14 @@ bool list_is_empty(struct list_head * h)
{
return h->nxt == h;
}
+
+void list_move(struct list_head * dst,
+ struct list_head * src)
+{
+ dst->nxt = src->nxt;
+ dst->prv = src->prv;
+ dst->nxt->prv = src->nxt->prv;
+ dst->prv->nxt = src->prv->nxt;
+
+ list_head_init(src);
+}