mirror of
https://gitlab.freedesktop.org/emersion/libliftoff.git
synced 2024-11-16 19:47:55 +01:00
43 lines
680 B
C
43 lines
680 B
C
#include "list.h"
|
|
|
|
void hwc_list_init(struct hwc_list *list)
|
|
{
|
|
list->prev = list;
|
|
list->next = list;
|
|
}
|
|
|
|
void hwc_list_insert(struct hwc_list *list, struct hwc_list *elm)
|
|
{
|
|
elm->prev = list;
|
|
elm->next = list->next;
|
|
list->next = elm;
|
|
elm->next->prev = elm;
|
|
}
|
|
|
|
void hwc_list_remove(struct hwc_list *elm)
|
|
{
|
|
elm->prev->next = elm->next;
|
|
elm->next->prev = elm->prev;
|
|
elm->next = NULL;
|
|
elm->prev = NULL;
|
|
}
|
|
|
|
size_t hwc_list_length(const struct hwc_list *list)
|
|
{
|
|
struct hwc_list *e;
|
|
size_t count;
|
|
|
|
count = 0;
|
|
e = list->next;
|
|
while (e != list) {
|
|
e = e->next;
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
bool hwc_list_empty(const struct hwc_list *list)
|
|
{
|
|
return list->next == list;
|
|
}
|