linked list rename mod to ex

This commit is contained in:
Krzosa Karol
2025-01-11 08:36:41 +01:00
parent e2d87d3631
commit fa3d59ed3e
2 changed files with 73 additions and 75 deletions

View File

@@ -124,7 +124,7 @@ typedef double f64;
#endif #endif
// Single linked list Queue // Single linked list Queue
#define SLLQ_APPEND_MOD(f, l, n, next) \ #define SLLQ_APPEND_EX(f, l, n, next) \
do { \ do { \
assert((n)->next == NULL); \ assert((n)->next == NULL); \
if ((f) == 0) { \ if ((f) == 0) { \
@@ -133,9 +133,9 @@ typedef double f64;
(l) = (l)->next = (n); \ (l) = (l)->next = (n); \
} \ } \
} while (0) } while (0)
#define SLLQ_APPEND(f, l, n) SLLQ_APPEND_MOD(f, l, n, next) #define SLLQ_APPEND(f, l, n) SLLQ_APPEND_EX(f, l, n, next)
#define SLLQ_PREPEND_MOD(f, l, n, next) \ #define SLLQ_PREPEND_EX(f, l, n, next) \
do { \ do { \
assert((n)->next == NULL); \ assert((n)->next == NULL); \
if ((f) == 0) { \ if ((f) == 0) { \
@@ -145,9 +145,9 @@ typedef double f64;
(f) = (n); \ (f) = (n); \
} \ } \
} while (0) } while (0)
#define SLLQ_PREPEND(f, l, n) SLLQ_PREPEND_MOD(f, l, n, next) #define SLLQ_PREPEND(f, l, n) SLLQ_PREPEND_EX(f, l, n, next)
#define SLLQ_REMOVE_FIRST_MOD(f, l, next) \ #define SLLQ_REMOVE_FIRST_EX(f, l, next) \
do { \ do { \
if ((f) == (l)) { \ if ((f) == (l)) { \
(f) = (l) = 0; \ (f) = (l) = 0; \
@@ -155,16 +155,16 @@ typedef double f64;
(f) = (f)->next; \ (f) = (f)->next; \
} \ } \
} while (0) } while (0)
#define SLLQ_REMOVE_FIRST(f, l) SLLQ_REMOVE_FIRST_MOD(f, l, next) #define SLLQ_REMOVE_FIRST(f, l) SLLQ_REMOVE_FIRST_EX(f, l, next)
// Singly linked list stack // Singly linked list stack
#define SLLS_PUSH_MOD(stack_base, new_stack_base, next) \ #define SLLS_PUSH_EX(stack_base, new_stack_base, next) \
do { \ do { \
(new_stack_base)->next = (stack_base); \ (new_stack_base)->next = (stack_base); \
(stack_base) = (new_stack_base); \ (stack_base) = (new_stack_base); \
} while (0) } while (0)
#define SLLS_PUSH(stack_base, new_stack_base) \ #define SLLS_PUSH(stack_base, new_stack_base) \
SLLS_PUSH_MOD(stack_base, new_stack_base, next) SLLS_PUSH_EX(stack_base, new_stack_base, next)
#define SLLS_POP_AND_STORE(stack_base, out_node) \ #define SLLS_POP_AND_STORE(stack_base, out_node) \
do { \ do { \
@@ -176,7 +176,7 @@ typedef double f64;
} while (0) } while (0)
// Doubly linked list Queue // Doubly linked list Queue
#define DLLQ_APPEND_MOD(f, l, node, next, prev) \ #define DLLQ_APPEND_EX(f, l, node, next, prev) \
do { \ do { \
assert((node)->next == NULL); \ assert((node)->next == NULL); \
assert((node)->prev == NULL); \ assert((node)->prev == NULL); \
@@ -188,9 +188,9 @@ typedef double f64;
(l) = (node); \ (l) = (node); \
} \ } \
} while (0) } while (0)
#define DLLQ_APPEND(f, l, node) DLLQ_APPEND_MOD(f, l, node, next, prev) #define DLLQ_APPEND(f, l, node) DLLQ_APPEND_EX(f, l, node, next, prev)
#define DLLQ_PREPEND_MOD(f, l, node, next, prev) \ #define DLLQ_PREPEND_EX(f, l, node, next, prev) \
do { \ do { \
assert((node)->next == NULL); \ assert((node)->next == NULL); \
assert((node)->prev == NULL); \ assert((node)->prev == NULL); \
@@ -202,11 +202,11 @@ typedef double f64;
(f) = (node); \ (f) = (node); \
} \ } \
} while (0) } while (0)
#define DLLQ_PREPEND(f, l, node) DLLQ_PREPEND_MOD(f, l, node, next, prev) #define DLLQ_PREPEND(f, l, node) DLLQ_PREPEND_EX(f, l, node, next, prev)
#define DLLQ_CONTAINS(f, l, n, next, prev) for ( #define DLLQ_CONTAINS(f, l, n, next, prev) for (
#define DLLQ_REMOVE_MOD(first, last, node, next, prev) \ #define DLLQ_REMOVE_EX(first, last, node, next, prev) \
do { \ do { \
if ((first) == (last)) { \ if ((first) == (last)) { \
assert((node) == (first)); \ assert((node) == (first)); \
@@ -226,10 +226,10 @@ typedef double f64;
(node)->next = 0; \ (node)->next = 0; \
} \ } \
} while (0) } while (0)
#define DLLQ_REMOVE(first, last, node) DLLQ_REMOVE_MOD(first, last, node, next, prev) #define DLLQ_REMOVE(first, last, node) DLLQ_REMOVE_EX(first, last, node, next, prev)
// Doubly linked list Stack // Doubly linked list Stack
#define DLLS_ADD_MOD(first, node, next, prev) \ #define DLLS_PUSH_EX(first, node, next, prev) \
do { \ do { \
assert((node)->next == NULL); \ assert((node)->next == NULL); \
assert((node)->prev == NULL); \ assert((node)->prev == NULL); \
@@ -238,8 +238,8 @@ typedef double f64;
(first)->prev = (node); \ (first)->prev = (node); \
(first) = (node); \ (first) = (node); \
} while (0) } while (0)
#define DLLS_ADD(first, node) DLLS_ADD_MOD(first, node, next, prev) #define DLLS_PUSH(first, node) DLLS_PUSH_EX(first, node, next, prev)
#define DLLS_REMOVE_MOD(first, node, next, prev) \ #define DLLS_REMOVE_EX(first, node, next, prev) \
do { \ do { \
if ((node) == (first)) { \ if ((node) == (first)) { \
(first) = (first)->next; \ (first) = (first)->next; \
@@ -255,5 +255,4 @@ typedef double f64;
(node)->next = 0; \ (node)->next = 0; \
} \ } \
} while (0) } while (0)
#define DLLS_REMOVE(first, node) DLLS_REMOVE_MOD(first, node, next, prev) #define DLLS_REMOVE(first, node) DLLS_REMOVE_EX(first, node, next, prev)

View File

@@ -49,7 +49,6 @@ struct ui_box_t {
r2f32_t rect; r2f32_t rect;
}; };
// @todo:
typedef struct ui_signal ui_signal; typedef struct ui_signal ui_signal;
struct ui_signal { struct ui_signal {
b8 clicked; b8 clicked;
@@ -106,7 +105,7 @@ ui_box_t *ui_build_box(ui_id_t id) {
memory_zero(box, offsetof(ui_box_t, id)); memory_zero(box, offsetof(ui_box_t, id));
} else { } else {
box = ui_alloc_box(); box = ui_alloc_box();
DLLQ_APPEND_MOD(ui->first_hash, ui->last_hash, box, hash_next, hash_prev); DLLQ_APPEND_EX(ui->first_hash, ui->last_hash, box, hash_next, hash_prev);
} }
box->last_frame_touched_index = ui->frame->frame; box->last_frame_touched_index = ui->frame->frame;
box->id = id; box->id = id;
@@ -293,7 +292,7 @@ void ui_end_frame(void) {
b32 touched_this_frame = ui->frame->frame <= box->last_frame_touched_index; b32 touched_this_frame = ui->frame->frame <= box->last_frame_touched_index;
b32 is_null = box->id.value == 0; b32 is_null = box->id.value == 0;
if (!touched_this_frame || is_null) { if (!touched_this_frame || is_null) {
DLLQ_REMOVE_MOD(ui->first_hash, ui->last_hash, box, hash_next, hash_prev); DLLQ_REMOVE_EX(ui->first_hash, ui->last_hash, box, hash_next, hash_prev);
zero_struct(box); zero_struct(box);
SLLS_PUSH(ui->first_free, box); SLLS_PUSH(ui->first_free, box);
} }