/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include "../../include/list.h" #include "../__internal/vnode.h" #ifndef LIBCDSB_SRC_LIST_INCLUDE_H #define LIBCDSB_SRC_LIST_INCLUDE_H typedef enum libcdsb_list_direction { LD_PREV = 1, LD_NEXT = 2 } ldir_t; typedef struct libcdsb_list_node { struct libcdsb_list_node* prev; struct libcdsb_list_node* next; vnode_t node; vtype type; } lnode_t; ainline(void libcdsb_builtin_init(list_t* x, vnode_t v, vtype t)) { lnode_t* node = malloc(sizeof(*node)); node->next = nullptr; node->prev = nullptr; node->node = v; node->type = t; x->first = node; x->last = node; } ainline(void libcdsb_builtin_push(list_t* x, vnode_t v, vtype t)) { lnode_t* node = malloc(sizeof(*node)); node->next = nullptr; node->prev = x->last; node->node = v; node->type = t; x->last->next = node; x->last = node; } #define ldir_dir(cur, d) (&((cur)->prev))[(d)>>1] #define ldir_inv(cur, d) (&((cur)->prev))[(d)&1] #define lnode_compare(s0, s1) vnode_compare(&(s0)->node, (s0)->type, &(s1)->node, (s1)->type) #endif /* LIBCDSB_SRC_LIST_INCLUDE_H */