diff options
Diffstat (limited to 'list')
| -rwxr-xr-x | list/list.c | 1 | ||||
| -rwxr-xr-x | list/list.h | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/list/list.c b/list/list.c index 4898790..c0f6c30 100755 --- a/list/list.c +++ b/list/list.c @@ -17,6 +17,7 @@ void _list_realloc(void **list, u32 n){ *list = (void*)nh+sizeof(struct list_header); } +// TODO look into removing adjusting the list size when the size decreases void _list_adjust(void **list){ struct list_header *h = list_header(*list); if(h == NULL) return; // TODO error warning?? diff --git a/list/list.h b/list/list.h index 9834ede..ded8193 100755 --- a/list/list.h +++ b/list/list.h @@ -73,6 +73,11 @@ enum LIST_TYPE { #define _choose_init(_1, _2, NAME, ...) NAME #define init_list(...) _choose_init(__VA_ARGS__, init_slist, init_dlist)(__VA_ARGS__) +#define list_size_increment(l) ({ \ + struct list_header *h = list_header(l); \ + if(h != NULL) h->size++; \ +}) + #define list_peek(l) ({ \ typeof((l)[0]) d = {0}; \ struct list_header *h = list_header(l); \ @@ -134,6 +139,7 @@ enum LIST_TYPE { found; \ }) +// TODO check for typeof #define list_push(l, d) ({ \ _list_adjust((void**)&(l)); \ struct list_header *h = list_header(l); \ @@ -145,6 +151,8 @@ enum LIST_TYPE { } \ }) +// TODO check for typeof +// TODO check i > 0 #define list_push_i(l, d, i) ({ \ _list_adjust((void**)&(l)); \ struct list_header *h = list_header(l); \ @@ -195,6 +203,16 @@ enum LIST_TYPE { } \ }) +// TODO encapsulate all indexes in parentheses in all macros +#define list_swap(l, i, j) ({ \ + struct list_header *h = list_header(l); \ + if(h != NULL && (i) != (j) && (i) >= 0 && (i) < h->size && (j) >= 0 && (j) < h->size){ \ + typeof((l)[0]) t = (l)[i]; \ + (l)[i] = (l)[j]; \ + (l)[j] = t; \ + } \ +}) + #define list_clamp_n(l, n) ({ \ struct list_header *h = list_header(l); \ if(h != NULL){ \ |
