#ifndef macros_h #define macros_h #undef assert #define assert(expr) if (!(expr)) { *(int *)0 = 0; } #define array_count(array) (sizeof(array)/sizeof(*(array))) #undef offsetof #define offsetof(type, element) ((u64)(&(((type *)0)->element))) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) #define clamp(a, x, b) \ (((x) < (a)) ? (a) : \ (((x) > (b)) ? (b) : (x))) #define swap(type, a, b) { type tmp = (a); (a) = (b); (b) = tmp; } #define kilobytes(n) n*1024 #define megabytes(n) kilobytes(n)*1024 #define gigabytes(n) megabytes(n)*1024 /* NOTE(pryazha): Singly linked list */ #define sllpush(first, last, node) \ ((first) == 0 ? \ ((first) = (last) = (node), (node)->next = 0) : \ ((last)->next = (node), (last) = (node), (node)->next = 0)) #define sllpop(first, last) \ ((first) == (last) ? \ ((first) = (last) = 0) : \ ((first) = (first)->next)) /* NOTE(pryazha): Doubly linked list */ #define dllpush(first, last, node, next, prev) \ ((first) == 0 ? \ ((first) = (last) = (node), (node)->next = (node)->prev = 0) : \ ((node)->prev = (last), (last)->next = (node), (last) = (node), (node)->next = 0)) #define dllpushback(first, last, node) dllpush(first, last, node, next, prev) #define dllpushfront(first, last, node) dllpush(last, first, node, prev, next) #define dllremove(first, last, node) \ ((first) == (node) ? \ ((first) == (last) ? (first) = (last) = 0 : \ ((first) = (first)->next, (first)->prev = 0)) : \ ((last) == (node) ? ((last) = (last)->prev, (last)->next = 0) : \ ((node)->next->prev = (node)->prev, (node)->prev->next = (node)->next))) #endif