rt/src/list.c

51 lines
1.1 KiB
C

#include <rt/list.h>
void rt_list_init(struct rt_list *list)
{
list->prev = list;
list->next = list;
}
bool rt_list_is_empty(const struct rt_list *list)
{
return list->next == list;
}
struct rt_list *rt_list_front(const struct rt_list *list)
{
return list->next;
}
void rt_list_push_back(struct rt_list *list, struct rt_list *node)
{
struct rt_list *const prev = list->prev;
list->prev = node;
prev->next = node;
node->prev = prev;
node->next = list;
}
void rt_list_remove(struct rt_list *node)
{
struct rt_list *const next = node->next, *const prev = node->prev;
node->prev = node;
node->next = node;
next->prev = prev;
prev->next = next;
}
void rt_list_insert_by(struct rt_list *list, struct rt_list *node,
bool (*cmp)(const struct rt_list *,
const struct rt_list *))
{
struct rt_list *next;
for (next = rt_list_front(list); next != list; next = next->next)
{
if (cmp(node, next))
{
break;
}
}
rt_list_push_back(next, node);
}