From f8217d240d598f39f70047f7a623dd46312542c6 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 Dec 2021 16:01:12 -0800 Subject: Initial commit. --- list/include/list.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 list/include/list.h (limited to 'list/include/list.h') diff --git a/list/include/list.h b/list/include/list.h new file mode 100644 index 0000000..b00b48b --- /dev/null +++ b/list/include/list.h @@ -0,0 +1,21 @@ +/// A doubly linked list. +/// +/// This list does not hold user data. Instead, the list can be used as an +/// intrusive list or as part as a more complex data structure. +#pragma once + +#include + +typedef struct list list; + +typedef struct list { + list* prev; + list* next; +} list; + +/// Create a new list from an array of `size` items. +void list_make(list* list, size_t size); + +/// Iterates over all the items in the list. +#define list_foreach(LIST, iter) \ + for (struct list* iter = LIST; iter; iter = iter->next) -- cgit v1.2.3