2019-08-21 22:07:37 +02:00
|
|
|
#include "list.h"
|
|
|
|
|
2021-08-13 22:02:33 +02:00
|
|
|
void
|
|
|
|
liftoff_list_init(struct liftoff_list *list)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
|
|
|
list->prev = list;
|
|
|
|
list->next = list;
|
|
|
|
}
|
|
|
|
|
2021-08-13 22:02:33 +02:00
|
|
|
void
|
|
|
|
liftoff_list_insert(struct liftoff_list *list, struct liftoff_list *elm)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
|
|
|
elm->prev = list;
|
|
|
|
elm->next = list->next;
|
|
|
|
list->next = elm;
|
|
|
|
elm->next->prev = elm;
|
|
|
|
}
|
|
|
|
|
2021-08-13 22:02:33 +02:00
|
|
|
void
|
|
|
|
liftoff_list_remove(struct liftoff_list *elm)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
|
|
|
elm->prev->next = elm->next;
|
|
|
|
elm->next->prev = elm->prev;
|
|
|
|
elm->next = NULL;
|
|
|
|
elm->prev = NULL;
|
|
|
|
}
|
|
|
|
|
2023-10-02 23:54:03 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-08-13 22:02:33 +02:00
|
|
|
size_t
|
|
|
|
liftoff_list_length(const struct liftoff_list *list)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_list *e;
|
2019-08-21 22:07:37 +02:00
|
|
|
size_t count;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
e = list->next;
|
|
|
|
while (e != list) {
|
|
|
|
e = e->next;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2021-08-13 22:02:33 +02:00
|
|
|
bool
|
|
|
|
liftoff_list_empty(const struct liftoff_list *list)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
|
|
|
return list->next == list;
|
|
|
|
}
|