mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2024-11-16 19:47:55 +01:00
Introduce liftoff_list_swap
Introduce a function to swap elements in a doubly linked list. This will be helpful when keeping the list of output layers sorted by priority. v2: re-define in terms of list_inserts and list_removes
This commit is contained in:
parent
19e56163c2
commit
a08c4d1f08
2 changed files with 16 additions and 0 deletions
|
@ -18,6 +18,9 @@ liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm);
|
|||
void
|
||||
liftoff_list_remove(struct liftoff_list *elm);
|
||||
|
||||
void
|
||||
liftoff_list_swap(struct liftoff_list *this, struct liftoff_list *other);
|
||||
|
||||
size_t
|
||||
liftoff_list_length(const struct liftoff_list *list);
|
||||
|
||||
|
|
13
list.c
13
list.c
|
@ -25,6 +25,19 @@ liftoff_list_remove(struct liftoff_list *elm)
|
|||
elm->prev = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
liftoff_list_swap(struct liftoff_list *this, struct liftoff_list *other)
|
||||
{
|
||||
struct liftoff_list tmp;
|
||||
|
||||
liftoff_list_insert(other, &tmp);
|
||||
liftoff_list_remove(other);
|
||||
liftoff_list_insert(this, other);
|
||||
liftoff_list_remove(this);
|
||||
liftoff_list_insert(&tmp, this);
|
||||
liftoff_list_remove(&tmp);
|
||||
}
|
||||
|
||||
size_t
|
||||
liftoff_list_length(const struct liftoff_list *list)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue