update stuff
This commit is contained in:
parent
6d36aa4442
commit
95d74c2ef4
13 changed files with 1196 additions and 48 deletions
41
core.h
41
core.h
|
|
@ -37,22 +37,35 @@ void colla_cleanup(void);
|
|||
|
||||
// LINKED LISTS /////////////////////////////////
|
||||
|
||||
#define list_push_n(list, item, next) ((item)->next=(list), (list)=(item))
|
||||
#define list_pop_n(list, next) ((list) = (list) ? (list)->next : NULL)
|
||||
// singly linked list
|
||||
#define list_push(list, item) ((item)->next=(list), (list)=(item))
|
||||
#define list_pop(list) ((list) = (list) ? (list)->next : NULL)
|
||||
|
||||
#define list_push(list, item) list_push_n(list, item, next)
|
||||
#define list_pop(list) list_pop_n(list, next)
|
||||
// double linked list
|
||||
#define dlist_push(list, item) do { \
|
||||
if (item) (item)->next = (list); \
|
||||
if (list) (list)->prev = (item); \
|
||||
(list) = (item); \
|
||||
} while (0)
|
||||
|
||||
#define dlist_push_pn(list, item, next, prev) if (item) (item)->next = (list); if (list) (list)->prev = (item); (list) = (item)
|
||||
#define dlist_pop_pn(list, item, next, prev) do { \
|
||||
if (!(item)) break; \
|
||||
if ((item)->prev) (item)->prev->next = (item)->next; \
|
||||
if ((item)->next) (item)->next->prev = (item)->prev; \
|
||||
if((item) == (list)) (list) = (item)->next; \
|
||||
} while (0)
|
||||
#define dlist_pop(list, item) do { \
|
||||
if (!(item)) break; \
|
||||
if ((item)->prev) (item)->prev->next = (item)->next; \
|
||||
if ((item)->next) (item)->next->prev = (item)->prev; \
|
||||
if ((item) == (list)) (list) = (item)->next; \
|
||||
} while (0)
|
||||
|
||||
#define dlist_push(list, item) dlist_push_pn(list, item, next, prev)
|
||||
#define dlist_pop(list, item) dlist_pop_pn(list, item, next, prev)
|
||||
// ordered linked list
|
||||
|
||||
#define olist_push(head, tail, item) do { \
|
||||
if (tail) { \
|
||||
(tail)->next = (item); \
|
||||
(tail) = (item); \
|
||||
} \
|
||||
else { \
|
||||
(head) = (tail) = (item); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define for_each(it, list) for (typeof(list) it = list; it; it = it->next)
|
||||
|
||||
|
|
@ -196,4 +209,4 @@ int fmt_bufferv(char *buf, usize len, const char *fmt, va_list args);
|
|||
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue